Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rss2email/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def setup_html2text(self, section='DEFAULT'):
('proxy', ''),
# Set the timeout (in seconds) for feed server response
('feed-timeout', str(60)),
# Set User Agent
('user-agent', ''),

### Processing
# True: Fetch, process, and email feeds.
Expand Down Expand Up @@ -193,6 +195,9 @@ def setup_html2text(self, section='DEFAULT'):
('imap-port', str(143)),
('imap-ssl', str(False)), # connect to the IMAP server using SSL
('imap-mailbox', 'INBOX'), # where we should store new messages
# Maildir configuration
('maildir-path', '~/Maildir'), # main maildir path
('maildir-mailbox', 'INBOX'), # for easier per-feed overrides

### Miscellaneous
# Verbosity (one of 'error', 'warning', 'info', or 'debug').
Expand Down
17 changes: 17 additions & 0 deletions rss2email/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@
from email.mime.text import MIMEText as _MIMEText
from email.utils import formataddr as _formataddr
from email.utils import parseaddr as _parseaddr
import mailbox as _mailbox
from mailbox import NoSuchMailboxError
import imaplib as _imaplib
import io as _io
import smtplib as _smtplib
import subprocess as _subprocess
import sys as _sys
import time as _time
import os as _os

from . import LOG as _LOG
from . import config as _config
Expand Down Expand Up @@ -199,6 +202,18 @@ def imap_send(message, config=None, section='DEFAULT'):
finally:
imap.logout()

def maildir_send(message, config=None, section='DEFAULT'):
if config is None:
config = _config.CONFIG
path = config.get(section, 'maildir-path')
mailbox = config.get(section, 'maildir-mailbox')
maildir = _mailbox.Maildir(path)
try:
maildir = maildir.get_folder(mailbox)
except NoSuchMailboxError:
maildir = maildir.add_folder(mailbox)
maildir.add(message)

def _decode_header(header):
"""Decode RFC-2047-encoded headers to Unicode strings

Expand Down Expand Up @@ -340,6 +355,8 @@ def send(sender, recipient, message, config=None, section='DEFAULT'):
config=config, section=section)
elif protocol == 'imap':
imap_send(message=message, config=config, section=section)
elif protocol == 'maildir':
maildir_send(message=message, config=config, section=section)
else:
sendmail_send(
sender=sender, recipient=recipient, message=message,
Expand Down
13 changes: 12 additions & 1 deletion rss2email/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,18 @@ def run(self, send=True):
"""
if not self.to:
raise _error.NoToEmailAddress(feed=self)
parsed = self._fetch()

if self.section in self.config:
config = self.config[self.section]
else:
config = self.config['DEFAULT']
agent = config['user-agent']
if agent:
_feedparser.USER_AGENT = agent
parsed = self._fetch()
_feedparser.USER_AGENT = _USER_AGENT
else:
parsed = self._fetch()

if self.digest:
digest = self._new_digest()
Expand Down