From: W. Trevor King Date: Sun, 14 Apr 2013 12:43:14 +0000 (-0400) Subject: email: Factor out Message-ID creation into get_id(). X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5d2fc6c49e908770209c2051509e7e069e74539a;p=rss2email.git email: Factor out Message-ID creation into get_id(). This will help us avoid duplicate code when we create Content-IDs. Signed-off-by: W. Trevor King --- diff --git a/rss2email/email.py b/rss2email/email.py index 46da48c..9e0034e 100644 --- a/rss2email/email.py +++ b/rss2email/email.py @@ -32,6 +32,7 @@ import io as _io import smtplib as _smtplib import subprocess as _subprocess import sys as _sys +import uuid as _uuid from . import LOG as _LOG from . import config as _config @@ -130,6 +131,15 @@ def set_headers(message, sender, recipient, subject, extra_headers=None, encoding = guess_encoding(value, encodings) message[key] = _Header(value, encoding) +def get_id(): + """Return a random, universally unique ID + + Conforming to RFC 2822 [1]. + + [1]: http://tools.ietf.org/html/rfc2822#section-3.6 + """ + return '<{}@dev.null.invalid>'.format(_uuid.uuid4()) + def get_mimetext(body, content_type='plain', config=None, section='DEFAULT'): """Generate a text/* `Message` instance. diff --git a/rss2email/feed.py b/rss2email/feed.py index 7cafde9..378a2ea 100644 --- a/rss2email/feed.py +++ b/rss2email/feed.py @@ -36,7 +36,6 @@ import socket as _socket import time as _time import urllib.error as _urllib_error import urllib.request as _urllib_request -import uuid as _uuid import xml.sax as _sax import xml.sax.saxutils as _saxutils @@ -408,7 +407,7 @@ class Feed (object): subject = self._get_entry_title(entry) extra_headers = _collections.OrderedDict(( ('Date', self._get_entry_date(entry)), - ('Message-ID', '<{}@dev.null.invalid>'.format(_uuid.uuid4())), + ('Message-ID', _email.get_id()), ('User-Agent', 'rss2email'), ('X-RSS-Feed', self.url), ('X-RSS-ID', id_),