rfc822

Parsing e-mail-like headers (similar to RFC822)

久未见 提交于 2019-12-02 04:41:24
问题 Problem / Question There is a database of bot information that I would like to parse. It is said to be similar to RFC822 messages. Before I re-invent the wheel and write a parser of my own, I figured I would see if something else was already available. I stumbled across imap_rfc822_parse_headers(), which seems to do exactly what I want. Unfortunately, the IMAP extension is not available in my environment. I have seen many alternatives online and on Stack Overflow. Unfortunately, they are all

Parsing e-mail-like headers (similar to RFC822)

ⅰ亾dé卋堺 提交于 2019-12-02 01:58:51
Problem / Question There is a database of bot information that I would like to parse. It is said to be similar to RFC822 messages . Before I re-invent the wheel and write a parser of my own, I figured I would see if something else was already available. I stumbled across imap_rfc822_parse_headers() , which seems to do exactly what I want. Unfortunately, the IMAP extension is not available in my environment. I have seen many alternatives online and on Stack Overflow. Unfortunately, they are all built for e-mail and do more than I need... often times parsing out an entire e-mail and handling

How do you extract multiple email addresses from an RFC 2822 mail header in python?

十年热恋 提交于 2019-12-01 21:27:32
Python's email module is great for parsing headers. However, the To: header can have multiple recipients, and there may be multiple To: headers. So how do I split out each of the email addresses? I can't split on the comma, since the comma can be quoted. Is there a way to do this? Demo code: msg="""To: user1@company1.com, "User Two" <user2@company2.com", "Three, User <user3@company3.com> From: anotheruser@user.com Subject: This is a subject This is the message. """ import email msg822 = email.message_from_string(msg) for to in msg822.get_all("To"): print("To:",to) Current output: $ python x.py

How do I elegantly print the date in RFC822 format in Perl?

若如初见. 提交于 2019-11-30 17:13:49
How can I elegantly print the date in RFC822 format in Perl? use POSIX qw(strftime); print strftime("%a, %d %b %Y %H:%M:%S %z", localtime(time())) . "\n"; The DateTime suite gives you a number of different ways, e.g.: use DateTime; print DateTime->now()->strftime("%a, %d %b %Y %H:%M:%S %z"); use DateTime::Format::Mail; print DateTime::Format::Mail->format_datetime( DateTime->now() ); print DateTime->now( formatter => DateTime::Format::Mail->new() ); Update: to give time for some particular timezone, add a time_zone argument to now(): DateTime->now( time_zone => $ENV{'TZ'}, ... ) It can be done

Elegant way to serialize a MailMessage object in .NET

拥有回忆 提交于 2019-11-30 06:59:41
问题 I'm currently looking at serializing a MailMessage object in C# and although there are a couple of variations of an example on the net, they serialize to binary which kind of misses the point IMO. My approach is that I'd like to serialize a MailMessage to an RFC2822 eml string and the code below is what I've come up with. public string SerializeEmail(MailMessageArgs e) { string rfc822eml = ""; Guid g = Guid.NewGuid(); lock (g.ToString()) { System.IO.DirectoryInfo di = new System.IO

How do I convert RFC822 to a python datetime object?

拜拜、爱过 提交于 2019-11-30 02:25:26
I know how to do this the other way around... it would be: >>> dt.rfc822() 'Sun, 09 Mar 1997 13:45:00 -0500' In [1]: import rfc822 # This only works for python 2 series In [2]: rfc822.parsedate_tz('Sun, 09 Mar 1997 13:45:00 -0500') Out[2]: (1997, 3, 9, 13, 45, 0, 0, 1, 0, -18000) in python3 parsedate_tz has moved to email.utils >>> import email.utils # this works on Python2.5 and up >>> email.utils.parsedate_tz('Sun, 09 Mar 1997 13:45:00 -0500') (1997, 3, 9, 13, 45, 0, 0, 1, -1, -18000) As of python 3.3 there is email.utils.parsedate_to_datetime(date) >>> from email.utils import parsedate_to

How do I elegantly print the date in RFC822 format in Perl?

穿精又带淫゛_ 提交于 2019-11-30 00:42:30
问题 How can I elegantly print the date in RFC822 format in Perl? 回答1: use POSIX qw(strftime); print strftime("%a, %d %b %Y %H:%M:%S %z", localtime(time())) . "\n"; 回答2: The DateTime suite gives you a number of different ways, e.g.: use DateTime; print DateTime->now()->strftime("%a, %d %b %Y %H:%M:%S %z"); use DateTime::Format::Mail; print DateTime::Format::Mail->format_datetime( DateTime->now() ); print DateTime->now( formatter => DateTime::Format::Mail->new() ); Update: to give time for some

How do I convert RFC822 to a python datetime object?

怎甘沉沦 提交于 2019-11-28 22:47:26
问题 I know how to do this the other way around... it would be: >>> dt.rfc822() 'Sun, 09 Mar 1997 13:45:00 -0500' 回答1: In [1]: import rfc822 # This only works for python 2 series In [2]: rfc822.parsedate_tz('Sun, 09 Mar 1997 13:45:00 -0500') Out[2]: (1997, 3, 9, 13, 45, 0, 0, 1, 0, -18000) in python3 parsedate_tz has moved to email.utils >>> import email.utils # this works on Python2.5 and up >>> email.utils.parsedate_tz('Sun, 09 Mar 1997 13:45:00 -0500') (1997, 3, 9, 13, 45, 0, 0, 1, -1, -18000)

How to do unfolding RFC 822

早过忘川 提交于 2019-11-28 10:47:33
问题 I am trying to write a vCard Parser and am having trouble unfolding lines. As you can see here: http://www.faqs.org/rfcs/rfc822.html look for "unfolding" it says that all the following are valid: Long string<return> <tab>continue Long string<return> <tab>(n*<tab>)continue Long string<return> <space>continue Long string<return> <space>(n*<space>)continue How do I unfold this? Is there a regex for this? I am using PHP if a class has been written I will use that :) 回答1: You could use this to

How can I get an email message's text content using Python?

白昼怎懂夜的黑 提交于 2019-11-27 11:21:20
Given an RFC822 message in Python 2.6, how can I get the right text/plain content part? Basically, the algorithm I want is this: message = email.message_from_string(raw_message) if has_mime_part(message, "text/plain"): mime_part = get_mime_part(message, "text/plain") text_content = decode_mime_part(mime_part) elif has_mime_part(message, "text/html"): mime_part = get_mime_part(message, "text/html") html = decode_mime_part(mime_part) text_content = render_html_to_plaintext(html) else: # fallback text_content = str(message) return text_content Of these things, I have get_mime_part and has_mime