From: François Boulogne Date: Wed, 2 Oct 2013 19:15:17 +0000 (+0200) Subject: post_process.redirect: Add support for enclosures X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=affcb256ebcd3a740d17236e40db1f08a4cd9071;p=rss2email.git post_process.redirect: Add support for enclosures Signed-off-by: François Boulogne --- 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