diff --git a/src/calibre/gui2/email.py b/src/calibre/gui2/email.py index 1f6fd44aed..8514720818 100644 --- a/src/calibre/gui2/email.py +++ b/src/calibre/gui2/email.py @@ -155,6 +155,8 @@ def email_news(mi, remove, get_fmts, done, job_manager): files = [f for f in files if f is not None] if not files: continue + if opts.tags.get(account, False) and not ({t.strip() for t in opts.tags[account].split(',')} & set(mi.tags)): + continue attachment = files[0] to_s = [account] subjects = [_('News:')+' '+mi.title] diff --git a/src/calibre/gui2/preferences/emailp.py b/src/calibre/gui2/preferences/emailp.py index 64b5af74c2..602aa4e659 100644 --- a/src/calibre/gui2/preferences/emailp.py +++ b/src/calibre/gui2/preferences/emailp.py @@ -20,16 +20,17 @@ from calibre.utils.smtp import config as smtp_prefs class EmailAccounts(QAbstractTableModel): # {{{ - def __init__(self, accounts, subjects, aliases={}): + def __init__(self, accounts, subjects, aliases={}, tags={}): QAbstractTableModel.__init__(self) self.accounts = accounts self.subjects = subjects self.aliases = aliases + self.tags = tags self.sorted_on = (0, True) self.account_order = self.accounts.keys() self.do_sort() self.headers = map(unicode, [_('Email'), _('Formats'), _('Subject'), - _('Auto send'), _('Alias')]) + _('Auto send'), _('Alias'), _('Auto send only tags')]) self.default_font = QFont() self.default_font.setBold(True) self.default_font = (self.default_font) @@ -40,9 +41,13 @@ class EmailAccounts(QAbstractTableModel): # {{{ 'templates used for "Save to disk" such as {title} and ' '{author_sort} can be used here.'), '
'+_('If checked, downloaded news will be automatically '
- 'mailed
to this email address '
- '(provided it is in one of the listed formats).'),
- _('Friendly name to use for this email address')
+ 'mailed to this email address '
+ '(provided it is in one of the listed formats and has not been filtered by tags).'),
+ _('Friendly name to use for this email address'),
+ _('If specified, only news with one of these tags will be sent to'
+ ' this email address. All news downloads have their title as a'
+ ' tag, so you can use this to easily control which news downloads'
+ ' are sent to this email address.')
])))
def do_sort(self):
@@ -62,6 +67,9 @@ class EmailAccounts(QAbstractTableModel): # {{{
elif col == 4:
def key(account_key):
return numeric_sort_key(self.aliases.get(account_key) or '')
+ elif col == 5:
+ def key(account_key):
+ return numeric_sort_key(self.tags.get(account_key) or '')
self.account_order.sort(key=key, reverse=not self.sorted_on[1])
def sort(self, column, order=Qt.AscendingOrder):
@@ -105,6 +113,8 @@ class EmailAccounts(QAbstractTableModel): # {{{
return (self.subjects.get(account, ''))
if col == 4:
return (self.aliases.get(account, ''))
+ if col == 5:
+ return (self.tags.get(account, ''))
if role == Qt.FontRole and self.accounts[account][2]:
return self.default_font
if role == Qt.CheckStateRole and col == 3:
@@ -131,6 +141,11 @@ class EmailAccounts(QAbstractTableModel): # {{{
aval = unicode(value or '').strip()
if aval:
self.aliases[account] = aval
+ elif col == 5:
+ self.tags.pop(account, None)
+ aval = unicode(value or '').strip()
+ if aval:
+ self.tags[account] = aval
elif col == 1:
self.accounts[account][0] = unicode(value or '').upper()
elif col == 0:
@@ -206,7 +221,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.send_email_widget.changed_signal.connect(self.changed_signal.emit)
opts = self.send_email_widget.smtp_opts
self._email_accounts = EmailAccounts(opts.accounts, opts.subjects,
- opts.aliases)
+ opts.aliases, opts.tags)
self._email_accounts.dataChanged.connect(lambda x,y:
self.changed_signal.emit())
self.email_view.setModel(self._email_accounts)
@@ -241,6 +256,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
self.proxy['accounts'] = self._email_accounts.accounts
self.proxy['subjects'] = self._email_accounts.subjects
self.proxy['aliases'] = self._email_accounts.aliases
+ self.proxy['tags'] = self._email_accounts.tags
return ConfigWidgetBase.commit(self)
diff --git a/src/calibre/utils/smtp.py b/src/calibre/utils/smtp.py
index 74b53cec13..ef8c4e8021 100644
--- a/src/calibre/utils/smtp.py
+++ b/src/calibre/utils/smtp.py
@@ -282,6 +282,7 @@ def config(defaults=None):
c.add_opt('accounts', default={})
c.add_opt('subjects', default={})
c.add_opt('aliases', default={})
+ c.add_opt('tags', default={})
c.add_opt('relay_host')
c.add_opt('relay_port', default=25)
c.add_opt('relay_username')