From affcb256ebcd3a740d17236e40db1f08a4cd9071 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fran=C3=A7ois=20Boulogne?= Date: Wed, 2 Oct 2013 21:15:17 +0200 Subject: [PATCH] post_process.redirect: Add support for enclosures MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: François Boulogne --- rss2email/post_process/redirect.py | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/rss2email/post_process/redirect.py b/rss2email/post_process/redirect.py index d06fcec..289fc65 100644 --- a/rss2email/post_process/redirect.py +++ b/rss2email/post_process/redirect.py @@ -31,19 +31,30 @@ def process(feed, parsed, entry, guid, message): encoding = message.get_charsets()[0] content = str(message.get_payload(decode=True), encoding) + links = [] + # Get the link link = entry['link'] - if not link: + if link: + links.append(link) + + for enclosure in entry['enclosures']: + links.append(enclosure['href']) + + if not links: return message # Remove the redirect and modify the content - try: - request = urllib.request.Request(link) - request.add_header('User-agent', rss2email.feed._USER_AGENT) - direct_link = urllib.request.urlopen(request).geturl() - except: - return message - content = re.sub(re.escape(link), direct_link, content, re.MULTILINE) + timeout = rss2email.config.CONFIG['DEFAULT'].getint('feed-timeout') + proxy = rss2email.config.CONFIG['DEFAULT']['proxy'] + for link in links: + try: + request = urllib.request.Request(link) + request.add_header('User-agent', rss2email.feed._USER_AGENT) + direct_link = urllib.request.urlopen(request).geturl() + except: + continue + content = re.sub(re.escape(link), direct_link, content, re.MULTILINE) # clear CTE and set message. It can be important to clear the CTE # before setting the payload, since the payload is only re-encoded -- 2.26.2