mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Support for email ebooks from calibre to your device. To use setup Email delivery in the preferences and then click the arrow next to the Send to Device button. Still experimental, so report bugs.
This commit is contained in:
parent
dbf89cb85e
commit
63ebe19a5f
@ -17,8 +17,10 @@ def option_parser():
|
|||||||
|
|
||||||
Run an embedded python interpreter.
|
Run an embedded python interpreter.
|
||||||
''')
|
''')
|
||||||
parser.add_option('--update-module', help='Update the specified module in the frozen library. '+
|
parser.add_option('--update-module',
|
||||||
'Module specifications are of the form full.name.of.module,path_to_module.py', default=None
|
help='Update the specified module in the frozen library. '+
|
||||||
|
'Module specifications are of the form full.name.of.module,path_to_module.py',
|
||||||
|
default=None
|
||||||
)
|
)
|
||||||
parser.add_option('-c', '--command', help='Run python code.', default=None)
|
parser.add_option('-c', '--command', help='Run python code.', default=None)
|
||||||
parser.add_option('-e', '--exec-file', default=None, help='Run the python code in file.')
|
parser.add_option('-e', '--exec-file', default=None, help='Run the python code in file.')
|
||||||
@ -27,7 +29,8 @@ Run an embedded python interpreter.
|
|||||||
parser.add_option('-g', '--gui', default=False, action='store_true',
|
parser.add_option('-g', '--gui', default=False, action='store_true',
|
||||||
help='Run the GUI',)
|
help='Run the GUI',)
|
||||||
parser.add_option('--migrate', action='store_true', default=False,
|
parser.add_option('--migrate', action='store_true', default=False,
|
||||||
help='Migrate old database. Needs two arguments. Path to library1.db and path to new library folder.')
|
help='Migrate old database. Needs two arguments. Path '
|
||||||
|
'to library1.db and path to new library folder.')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def update_zipfile(zipfile, mod, path):
|
def update_zipfile(zipfile, mod, path):
|
||||||
|
@ -4,7 +4,7 @@ __copyright__ = '2009, John Schember <john at nachtimwald.com>'
|
|||||||
Device driver for Amazon's Kindle
|
Device driver for Amazon's Kindle
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os, re
|
import os, re, sys
|
||||||
|
|
||||||
from calibre.devices.usbms.driver import USBMS, metadata_from_formats
|
from calibre.devices.usbms.driver import USBMS, metadata_from_formats
|
||||||
|
|
||||||
@ -51,6 +51,9 @@ class KINDLE(USBMS):
|
|||||||
match = cls.WIRELESS_FILE_NAME_PATTERN.match(os.path.basename(path))
|
match = cls.WIRELESS_FILE_NAME_PATTERN.match(os.path.basename(path))
|
||||||
if match is not None:
|
if match is not None:
|
||||||
mi.title = match.group('title')
|
mi.title = match.group('title')
|
||||||
|
if not isinstance(mi.title, unicode):
|
||||||
|
mi.title = mi.title.decode(sys.getfilesystemencoding(),
|
||||||
|
'replace')
|
||||||
return mi
|
return mi
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,8 +38,10 @@ class UnsupportedFormatError(Exception):
|
|||||||
class SpineItem(unicode):
|
class SpineItem(unicode):
|
||||||
|
|
||||||
def __new__(cls, *args):
|
def __new__(cls, *args):
|
||||||
|
args = list(args)
|
||||||
|
args[0] = args[0].partition('#')[0]
|
||||||
obj = super(SpineItem, cls).__new__(cls, *args)
|
obj = super(SpineItem, cls).__new__(cls, *args)
|
||||||
path = args[0].partition('#')[0]
|
path = args[0]
|
||||||
raw = open(path, 'rb').read()
|
raw = open(path, 'rb').read()
|
||||||
raw, obj.encoding = xml_to_unicode(raw)
|
raw, obj.encoding = xml_to_unicode(raw)
|
||||||
obj.character_count = character_count(raw)
|
obj.character_count = character_count(raw)
|
||||||
@ -67,6 +69,7 @@ class EbookIterator(object):
|
|||||||
CHARACTERS_PER_PAGE = 1000
|
CHARACTERS_PER_PAGE = 1000
|
||||||
|
|
||||||
def __init__(self, pathtoebook):
|
def __init__(self, pathtoebook):
|
||||||
|
pathtoebook = pathtoebook.strip()
|
||||||
self.pathtoebook = os.path.abspath(pathtoebook)
|
self.pathtoebook = os.path.abspath(pathtoebook)
|
||||||
self.config = DynamicConfig(name='iterator')
|
self.config = DynamicConfig(name='iterator')
|
||||||
ext = os.path.splitext(pathtoebook)[1].replace('.', '').lower()
|
ext = os.path.splitext(pathtoebook)[1].replace('.', '').lower()
|
||||||
|
@ -8,7 +8,7 @@ import sys, re, socket
|
|||||||
from urllib import urlopen, quote
|
from urllib import urlopen, quote
|
||||||
|
|
||||||
from calibre.utils.config import OptionParser
|
from calibre.utils.config import OptionParser
|
||||||
from calibre.ebooks.metadata import MetaInformation, authors_to_sort_string
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
from calibre.ebooks.BeautifulSoup import BeautifulStoneSoup
|
from calibre.ebooks.BeautifulSoup import BeautifulStoneSoup
|
||||||
|
|
||||||
BASE_URL = 'http://isbndb.com/api/books.xml?access_key=%(key)s&page_number=1&results=subjects,authors,texts&'
|
BASE_URL = 'http://isbndb.com/api/books.xml?access_key=%(key)s&page_number=1&results=subjects,authors,texts&'
|
||||||
|
@ -9,7 +9,7 @@ lxml based OPF parser.
|
|||||||
|
|
||||||
import sys, unittest, functools, os, mimetypes, uuid, glob, cStringIO
|
import sys, unittest, functools, os, mimetypes, uuid, glob, cStringIO
|
||||||
from urllib import unquote
|
from urllib import unquote
|
||||||
from urlparse import urlparse
|
from urlparse import urlparse, urldefrag
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from dateutil import parser
|
from dateutil import parser
|
||||||
@ -444,7 +444,7 @@ class OPF(object):
|
|||||||
if not hasattr(stream, 'read'):
|
if not hasattr(stream, 'read'):
|
||||||
stream = open(stream, 'rb')
|
stream = open(stream, 'rb')
|
||||||
self.basedir = self.base_dir = basedir
|
self.basedir = self.base_dir = basedir
|
||||||
self.path_to_html_toc = None
|
self.path_to_html_toc = self.html_toc_fragment = None
|
||||||
raw, self.encoding = xml_to_unicode(stream.read(), strip_encoding_pats=True, resolve_entities=True)
|
raw, self.encoding = xml_to_unicode(stream.read(), strip_encoding_pats=True, resolve_entities=True)
|
||||||
raw = raw[raw.find('<'):]
|
raw = raw[raw.find('<'):]
|
||||||
self.root = etree.fromstring(raw, self.PARSER)
|
self.root = etree.fromstring(raw, self.PARSER)
|
||||||
@ -496,7 +496,8 @@ class OPF(object):
|
|||||||
if f:
|
if f:
|
||||||
self.toc.read_ncx_toc(f[0])
|
self.toc.read_ncx_toc(f[0])
|
||||||
else:
|
else:
|
||||||
self.path_to_html_toc = toc
|
self.path_to_html_toc, self.html_toc_fragment = \
|
||||||
|
toc.partition('#')[0], toc.partition('#')[-1]
|
||||||
self.toc.read_html_toc(toc)
|
self.toc.read_html_toc(toc)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,16 +1,15 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
""" The GUI """
|
""" The GUI """
|
||||||
import sys, os, re, StringIO, traceback, time
|
import os
|
||||||
from PyQt4.QtCore import QVariant, QFileInfo, QObject, SIGNAL, QBuffer, Qt, QSize, \
|
from PyQt4.QtCore import QVariant, QFileInfo, QObject, SIGNAL, QBuffer, Qt, QSize, \
|
||||||
QByteArray, QLocale, QUrl, QTranslator, QCoreApplication, \
|
QByteArray, QUrl, QTranslator, QCoreApplication
|
||||||
QModelIndex
|
|
||||||
from PyQt4.QtGui import QFileDialog, QMessageBox, QPixmap, QFileIconProvider, \
|
from PyQt4.QtGui import QFileDialog, QMessageBox, QPixmap, QFileIconProvider, \
|
||||||
QIcon, QTableView, QDialogButtonBox, QApplication, QDialog
|
QIcon, QTableView, QApplication, QDialog
|
||||||
|
|
||||||
ORG_NAME = 'KovidsBrain'
|
ORG_NAME = 'KovidsBrain'
|
||||||
APP_UID = 'libprs500'
|
APP_UID = 'libprs500'
|
||||||
from calibre import __author__, islinux, iswindows, isosx
|
from calibre import islinux, iswindows
|
||||||
from calibre.startup import get_lang
|
from calibre.startup import get_lang
|
||||||
from calibre.utils.config import Config, ConfigProxy, dynamic
|
from calibre.utils.config import Config, ConfigProxy, dynamic
|
||||||
import calibre.resources as resources
|
import calibre.resources as resources
|
||||||
@ -65,6 +64,9 @@ def _config():
|
|||||||
help=_('Show the cover flow in a separate window instead of in the main calibre window'))
|
help=_('Show the cover flow in a separate window instead of in the main calibre window'))
|
||||||
c.add_opt('disable_tray_notification', default=False,
|
c.add_opt('disable_tray_notification', default=False,
|
||||||
help=_('Disable notifications from the system tray icon'))
|
help=_('Disable notifications from the system tray icon'))
|
||||||
|
c.add_opt('default_send_to_device_action', default=None,
|
||||||
|
help=_('Default action to perform when send to device button is '
|
||||||
|
'clicked'))
|
||||||
return ConfigProxy(c)
|
return ConfigProxy(c)
|
||||||
|
|
||||||
config = _config()
|
config = _config()
|
||||||
@ -139,15 +141,15 @@ def human_readable(size):
|
|||||||
|
|
||||||
class Dispatcher(QObject):
|
class Dispatcher(QObject):
|
||||||
'''Convenience class to ensure that a function call always happens in the GUI thread'''
|
'''Convenience class to ensure that a function call always happens in the GUI thread'''
|
||||||
|
SIGNAL = SIGNAL('dispatcher(PyQt_PyObject,PyQt_PyObject)')
|
||||||
|
|
||||||
def __init__(self, func):
|
def __init__(self, func):
|
||||||
QObject.__init__(self)
|
QObject.__init__(self)
|
||||||
self.func = func
|
self.func = func
|
||||||
self.connect(self, SIGNAL('edispatch(PyQt_PyObject, PyQt_PyObject)'),
|
self.connect(self, self.SIGNAL, self.dispatch, Qt.QueuedConnection)
|
||||||
self.dispatch, Qt.QueuedConnection)
|
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
self.emit(SIGNAL('edispatch(PyQt_PyObject, PyQt_PyObject)'), args, kwargs)
|
self.emit(self.SIGNAL, args, kwargs)
|
||||||
|
|
||||||
def dispatch(self, args, kwargs):
|
def dispatch(self, args, kwargs):
|
||||||
self.func(*args, **kwargs)
|
self.func(*args, **kwargs)
|
||||||
@ -447,6 +449,7 @@ class ResizableDialog(QDialog):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from calibre.utils.single_qt_application import SingleApplication
|
from calibre.utils.single_qt_application import SingleApplication
|
||||||
|
SingleApplication
|
||||||
except:
|
except:
|
||||||
SingleApplication = None
|
SingleApplication = None
|
||||||
|
|
||||||
|
@ -1,12 +1,28 @@
|
|||||||
|
from __future__ import with_statement
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
import os, traceback, Queue, time
|
import os, traceback, Queue, time, socket
|
||||||
from threading import Thread
|
from threading import Thread, RLock
|
||||||
|
from itertools import repeat
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
|
from PyQt4.Qt import QMenu, QAction, QActionGroup, QIcon, SIGNAL, QPixmap, \
|
||||||
|
Qt
|
||||||
|
|
||||||
from calibre.devices import devices
|
from calibre.devices import devices
|
||||||
|
from calibre.gui2.dialogs.choose_format import ChooseFormatDialog
|
||||||
from calibre.parallel import Job
|
from calibre.parallel import Job
|
||||||
from calibre.devices.scanner import DeviceScanner
|
from calibre.devices.scanner import DeviceScanner
|
||||||
|
from calibre.gui2 import config, error_dialog, Dispatcher, dynamic, \
|
||||||
|
pixmap_to_data, warning_dialog
|
||||||
|
from calibre.ebooks.metadata import authors_to_string
|
||||||
|
from calibre.gui2.dialogs.conversion_error import ConversionErrorDialog
|
||||||
|
from calibre.devices.interface import Device
|
||||||
|
from calibre import sanitize_file_name, preferred_encoding
|
||||||
|
from calibre.utils.filenames import ascii_filename
|
||||||
|
from calibre.devices.errors import FreeSpaceError
|
||||||
|
from calibre.utils.smtp import compose_mail, sendmail, extract_email_address, \
|
||||||
|
config as email_config
|
||||||
|
|
||||||
class DeviceJob(Job):
|
class DeviceJob(Job):
|
||||||
|
|
||||||
@ -26,11 +42,7 @@ class DeviceJob(Job):
|
|||||||
|
|
||||||
|
|
||||||
class DeviceManager(Thread):
|
class DeviceManager(Thread):
|
||||||
'''
|
|
||||||
Worker thread that polls the USB ports for devices. Emits the
|
|
||||||
signal connected(PyQt_PyObject, PyQt_PyObject) on connection and
|
|
||||||
disconnection events.
|
|
||||||
'''
|
|
||||||
def __init__(self, connected_slot, job_manager, sleep_time=2):
|
def __init__(self, connected_slot, job_manager, sleep_time=2):
|
||||||
'''
|
'''
|
||||||
@param sleep_time: Time to sleep between device probes in millisecs
|
@param sleep_time: Time to sleep between device probes in millisecs
|
||||||
@ -104,6 +116,12 @@ class DeviceManager(Thread):
|
|||||||
self.jobs.put(job)
|
self.jobs.put(job)
|
||||||
return job
|
return job
|
||||||
|
|
||||||
|
def has_card(self):
|
||||||
|
try:
|
||||||
|
return bool(self.device.card_prefix())
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
def _get_device_information(self):
|
def _get_device_information(self):
|
||||||
info = self.device.get_device_information(end_session=False)
|
info = self.device.get_device_information(end_session=False)
|
||||||
info = [i.replace('\x00', '').replace('\x01', '') for i in info]
|
info = [i.replace('\x00', '').replace('\x01', '') for i in info]
|
||||||
@ -116,7 +134,6 @@ class DeviceManager(Thread):
|
|||||||
return self.create_job(self._get_device_information, done,
|
return self.create_job(self._get_device_information, done,
|
||||||
description=_('Get device information'))
|
description=_('Get device information'))
|
||||||
|
|
||||||
|
|
||||||
def _books(self):
|
def _books(self):
|
||||||
'''Get metadata from device'''
|
'''Get metadata from device'''
|
||||||
mainlist = self.device.books(oncard=False, end_session=False)
|
mainlist = self.device.books(oncard=False, end_session=False)
|
||||||
@ -185,3 +202,454 @@ class DeviceManager(Thread):
|
|||||||
return self.create_job(self._view_book, done, args=[path, target],
|
return self.create_job(self._view_book, done, args=[path, target],
|
||||||
description=_('View book on device'))
|
description=_('View book on device'))
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceAction(QAction):
|
||||||
|
|
||||||
|
def __init__(self, dest, delete, specific, icon_path, text, parent=None):
|
||||||
|
if delete:
|
||||||
|
text += ' ' + _('and delete from library')
|
||||||
|
QAction.__init__(self, QIcon(icon_path), text, parent)
|
||||||
|
self.dest = dest
|
||||||
|
self.delete = delete
|
||||||
|
self.specific = specific
|
||||||
|
self.connect(self, SIGNAL('triggered(bool)'),
|
||||||
|
lambda x : self.emit(SIGNAL('a_s(QAction)'), self))
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return self.__class__.__name__ + ':%s:%s:%s'%(self.dest, self.delete,
|
||||||
|
self.specific)
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceMenu(QMenu):
|
||||||
|
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
QMenu.__init__(self, parent)
|
||||||
|
self.group = QActionGroup(self)
|
||||||
|
self.actions = []
|
||||||
|
self._memory = []
|
||||||
|
|
||||||
|
self.set_default_menu = self.addMenu(_('Set default send to device'
|
||||||
|
' action'))
|
||||||
|
opts = email_config().parse()
|
||||||
|
default_account = None
|
||||||
|
if opts.accounts:
|
||||||
|
self.email_to_menu = self.addMenu(_('Email to')+'...')
|
||||||
|
keys = sorted(opts.accounts.keys())
|
||||||
|
for account in keys:
|
||||||
|
formats, auto, default = opts.accounts[account]
|
||||||
|
dest = 'mail:'+account+';'+formats
|
||||||
|
if default:
|
||||||
|
default_account = (dest, False, False, ':/images/mail.svg',
|
||||||
|
_('Email to')+' '+account)
|
||||||
|
action1 = DeviceAction(dest, False, False, ':/images/mail.svg',
|
||||||
|
_('Email to')+' '+account, self)
|
||||||
|
action2 = DeviceAction(dest, True, False, ':/images/mail.svg',
|
||||||
|
_('Email to')+' '+account, self)
|
||||||
|
map(self.email_to_menu.addAction, (action1, action2))
|
||||||
|
map(self._memory.append, (action1, action2))
|
||||||
|
self.email_to_menu.addSeparator()
|
||||||
|
self.connect(action1, SIGNAL('a_s(QAction)'),
|
||||||
|
self.action_triggered)
|
||||||
|
self.connect(action2, SIGNAL('a_s(QAction)'),
|
||||||
|
self.action_triggered)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
_actions = [
|
||||||
|
('main:', False, False, ':/images/reader.svg',
|
||||||
|
_('Send to main memory')),
|
||||||
|
('card:0', False, False, ':/images/sd.svg',
|
||||||
|
_('Send to storage card')),
|
||||||
|
'-----',
|
||||||
|
('main:', True, False, ':/images/reader.svg',
|
||||||
|
_('Send to main memory')),
|
||||||
|
('card:0', True, False, ':/images/sd.svg',
|
||||||
|
_('Send to storage card')),
|
||||||
|
'-----',
|
||||||
|
('main:', False, True, ':/images/reader.svg',
|
||||||
|
_('Send specific format to main memory')),
|
||||||
|
('card:0', False, True, ':/images/sd.svg',
|
||||||
|
_('Send specific format to storage card')),
|
||||||
|
|
||||||
|
]
|
||||||
|
if default_account is not None:
|
||||||
|
_actions.insert(2, default_account)
|
||||||
|
_actions.insert(6, list(default_account))
|
||||||
|
_actions[6][1] = True
|
||||||
|
for round in (0, 1):
|
||||||
|
for dest, delete, specific, icon, text in _actions:
|
||||||
|
if dest == '-':
|
||||||
|
(self.set_default_menu if round else self).addSeparator()
|
||||||
|
continue
|
||||||
|
action = DeviceAction(dest, delete, specific, icon, text, self)
|
||||||
|
self._memory.append(action)
|
||||||
|
if round == 1:
|
||||||
|
action.setCheckable(True)
|
||||||
|
action.setText(action.text())
|
||||||
|
self.group.addAction(action)
|
||||||
|
self.set_default_menu.addAction(action)
|
||||||
|
else:
|
||||||
|
self.connect(action, SIGNAL('a_s(QAction)'),
|
||||||
|
self.action_triggered)
|
||||||
|
self.actions.append(action)
|
||||||
|
self.addAction(action)
|
||||||
|
|
||||||
|
|
||||||
|
da = config['default_send_to_device_action']
|
||||||
|
done = False
|
||||||
|
for action in self.group.actions():
|
||||||
|
if repr(action) == da:
|
||||||
|
action.setChecked(True)
|
||||||
|
done = True
|
||||||
|
break
|
||||||
|
if not done:
|
||||||
|
action = list(self.group.actions())[0]
|
||||||
|
action.setChecked(True)
|
||||||
|
config['default_send_to_device_action'] = repr(action)
|
||||||
|
|
||||||
|
self.connect(self.group, SIGNAL('triggered(QAction*)'),
|
||||||
|
self.change_default_action)
|
||||||
|
self.enable_device_actions(False)
|
||||||
|
if opts.accounts:
|
||||||
|
self.addSeparator()
|
||||||
|
self.addMenu(self.email_to_menu)
|
||||||
|
|
||||||
|
def change_default_action(self, action):
|
||||||
|
config['default_send_to_device_action'] = repr(action)
|
||||||
|
action.setChecked(True)
|
||||||
|
|
||||||
|
def action_triggered(self, action):
|
||||||
|
self.emit(SIGNAL('sync(PyQt_PyObject, PyQt_PyObject, PyQt_PyObject)'),
|
||||||
|
action.dest, action.delete, action.specific)
|
||||||
|
|
||||||
|
def trigger_default(self, *args):
|
||||||
|
r = config['default_send_to_device_action']
|
||||||
|
for action in self.actions:
|
||||||
|
if repr(action) == r:
|
||||||
|
self.action_triggered(action)
|
||||||
|
break
|
||||||
|
|
||||||
|
def enable_device_actions(self, enable):
|
||||||
|
for action in self.actions:
|
||||||
|
if action.dest[:4] in ('main', 'card'):
|
||||||
|
action.setEnabled(enable)
|
||||||
|
|
||||||
|
class Emailer(Thread):
|
||||||
|
|
||||||
|
def __init__(self, timeout=10):
|
||||||
|
Thread.__init__(self)
|
||||||
|
self.setDaemon(True)
|
||||||
|
self.job_lock = RLock()
|
||||||
|
self.jobs = []
|
||||||
|
self._run = True
|
||||||
|
self.timeout = timeout
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
while self._run:
|
||||||
|
job = None
|
||||||
|
with self.job_lock:
|
||||||
|
if self.jobs:
|
||||||
|
job = self.jobs[0]
|
||||||
|
self.jobs = self.jobs[1:]
|
||||||
|
if job is not None:
|
||||||
|
self._send_mails(*job)
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self._run = False
|
||||||
|
|
||||||
|
def send_mails(self, jobnames, callback, attachments, to_s, subjects,
|
||||||
|
texts, attachment_names):
|
||||||
|
job = (jobnames, callback, attachments, to_s, subjects, texts,
|
||||||
|
attachment_names)
|
||||||
|
with self.job_lock:
|
||||||
|
self.jobs.append(job)
|
||||||
|
|
||||||
|
def _send_mails(self, jobnames, callback, attachments,
|
||||||
|
to_s, subjects, texts, attachment_names):
|
||||||
|
opts = email_config().parse()
|
||||||
|
from_ = opts.from_
|
||||||
|
if not from_:
|
||||||
|
from_ = 'calibre <calibre@'+socket.getfqdn()+'>'
|
||||||
|
results = []
|
||||||
|
for i, jobname in enumerate(jobnames):
|
||||||
|
try:
|
||||||
|
msg = compose_mail(from_, to_s[i], texts[i], subjects[i],
|
||||||
|
open(attachments[i], 'rb'),
|
||||||
|
attachment_name = attachment_names[i])
|
||||||
|
efrom, eto = map(extract_email_address, (from_, to_s[i]))
|
||||||
|
eto = [eto]
|
||||||
|
sendmail(msg, efrom, eto, localhost=None, verbose=0,
|
||||||
|
timeout=self.timeout, relay=opts.relay_host,
|
||||||
|
username=opts.relay_username,
|
||||||
|
password=opts.relay_password, port=opts.relay_port,
|
||||||
|
encryption=opts.encryption)
|
||||||
|
results.append([jobname, None, None])
|
||||||
|
except Exception, e:
|
||||||
|
results.append([jobname, e, traceback.format_exc()])
|
||||||
|
callback(results)
|
||||||
|
|
||||||
|
|
||||||
|
class DeviceGUI(object):
|
||||||
|
|
||||||
|
def dispatch_sync_event(self, dest, delete, specific):
|
||||||
|
rows = self.library_view.selectionModel().selectedRows()
|
||||||
|
if not rows or len(rows) == 0:
|
||||||
|
error_dialog(self, _('No books'), _('No books')+' '+\
|
||||||
|
_('selected to send')).exec_()
|
||||||
|
return
|
||||||
|
|
||||||
|
fmt = None
|
||||||
|
if specific:
|
||||||
|
d = ChooseFormatDialog(self, _('Choose format to send to device'),
|
||||||
|
self.device_manager.device_class.FORMATS)
|
||||||
|
d.exec_()
|
||||||
|
fmt = d.format().lower()
|
||||||
|
dest, sub_dest = dest.split(':')
|
||||||
|
if dest in ('main', 'card'):
|
||||||
|
if not self.device_connected or not self.device_manager:
|
||||||
|
error_dialog(self, _('No device'),
|
||||||
|
_('Cannot send: No device is connected')).exec_()
|
||||||
|
return
|
||||||
|
on_card = dest == 'card'
|
||||||
|
if on_card and not self.device_manager.has_card():
|
||||||
|
error_dialog(self, _('No card'),
|
||||||
|
_('Cannot send: Device has no storage card')).exec_()
|
||||||
|
return
|
||||||
|
self.sync_to_device(on_card, delete, fmt)
|
||||||
|
elif dest == 'mail':
|
||||||
|
to, fmts = sub_dest.split(';')
|
||||||
|
fmts = [x.strip().lower() for x in fmts.split(',')]
|
||||||
|
self.send_by_mail(to, fmts, delete)
|
||||||
|
|
||||||
|
def send_by_mail(self, to, fmts, delete_from_library):
|
||||||
|
rows = self.library_view.selectionModel().selectedRows()
|
||||||
|
if not rows or len(rows) == 0:
|
||||||
|
return
|
||||||
|
ids = iter(self.library_view.model().id(r) for r in rows)
|
||||||
|
full_metadata = self.library_view.model().get_metadata(
|
||||||
|
rows, full_metadata=True)[-1]
|
||||||
|
files = self.library_view.model().get_preferred_formats(rows,
|
||||||
|
fmts, paths=True, set_metadata=True)
|
||||||
|
files = [getattr(f, 'name', None) for f in files]
|
||||||
|
|
||||||
|
bad, remove_ids, jobnames = [], [], []
|
||||||
|
texts, subjects, attachments, attachment_names = [], [], [], []
|
||||||
|
for f, mi, id in zip(files, full_metadata, ids):
|
||||||
|
t = mi.title
|
||||||
|
if not t:
|
||||||
|
t = _('Unknown')
|
||||||
|
if f is None:
|
||||||
|
bad.append(t)
|
||||||
|
else:
|
||||||
|
remove_ids.append(id)
|
||||||
|
jobnames.append(u'%s:%s'%(id, t))
|
||||||
|
attachments.append(f)
|
||||||
|
subjects.append(_('E-book:')+ ' '+t)
|
||||||
|
a = authors_to_string(mi.authors if mi.authors else \
|
||||||
|
[_('Unknown')])
|
||||||
|
texts.append(_('Attached, you will find the e-book') + \
|
||||||
|
'\n\n' + t + '\n\t' + _('by') + ' ' + a + '\n\n' + \
|
||||||
|
_('in the %s format.') %
|
||||||
|
os.path.splitext(f)[1][1:].upper())
|
||||||
|
prefix = sanitize_file_name(t+' - '+a)
|
||||||
|
if not isinstance(prefix, unicode):
|
||||||
|
prefix = prefix.decode(preferred_encoding, 'replace')
|
||||||
|
attachment_names.append(prefix + os.path.splitext(f)[1])
|
||||||
|
remove = remove_ids if delete_from_library else []
|
||||||
|
|
||||||
|
to_s = list(repeat(to, len(attachments)))
|
||||||
|
if attachments:
|
||||||
|
self.emailer.send_mails(jobnames,
|
||||||
|
Dispatcher(partial(self.emails_sent, remove=remove)),
|
||||||
|
attachments, to_s, subjects, texts, attachment_names)
|
||||||
|
self.status_bar.showMessage(_('Sending email to')+' '+to, 3000)
|
||||||
|
|
||||||
|
if bad:
|
||||||
|
bad = '\n'.join('<li>%s</li>'%(i,) for i in bad)
|
||||||
|
d = warning_dialog(self, _('No suitable formats'),
|
||||||
|
'<p>'+ _('Could not email the following books '
|
||||||
|
'as no suitable formats were found:<br><ul>%s</ul>')%(bad,))
|
||||||
|
d.exec_()
|
||||||
|
|
||||||
|
def emails_sent(self, results, remove=[]):
|
||||||
|
errors, good = [], []
|
||||||
|
for jobname, exception, tb in results:
|
||||||
|
id = jobname.partition(':')[0]
|
||||||
|
title = jobname.partition(':')[-1]
|
||||||
|
if exception is not None:
|
||||||
|
errors.append([title, exception, tb])
|
||||||
|
else:
|
||||||
|
good.append(title)
|
||||||
|
if errors:
|
||||||
|
errors = '\n'.join([
|
||||||
|
'<li><b>%s</b><br>%s<br>%s<br></li>' %
|
||||||
|
(title, e, tb.replace('\n', '<br>')) for \
|
||||||
|
title, e, tb in errors
|
||||||
|
])
|
||||||
|
ConversionErrorDialog(self, _('Failed to email books'),
|
||||||
|
'<p>'+_('Failed to email the following books:')+\
|
||||||
|
'<ul>%s</ul>'%errors,
|
||||||
|
show=True)
|
||||||
|
else:
|
||||||
|
self.status_bar.showMessage(_('Sent by email:') + ', '.join(good),
|
||||||
|
5000)
|
||||||
|
|
||||||
|
def cover_to_thumbnail(self, data):
|
||||||
|
p = QPixmap()
|
||||||
|
p.loadFromData(data)
|
||||||
|
if not p.isNull():
|
||||||
|
ht = self.device_manager.device_class.THUMBNAIL_HEIGHT \
|
||||||
|
if self.device_manager else Device.THUMBNAIL_HEIGHT
|
||||||
|
p = p.scaledToHeight(ht, Qt.SmoothTransformation)
|
||||||
|
return (p.width(), p.height(), pixmap_to_data(p))
|
||||||
|
|
||||||
|
def sync_news(self):
|
||||||
|
if self.device_connected:
|
||||||
|
ids = list(dynamic.get('news_to_be_synced', set([])))
|
||||||
|
ids = [id for id in ids if self.library_view.model().db.has_id(id)]
|
||||||
|
files = self.library_view.model().get_preferred_formats_from_ids(
|
||||||
|
ids, self.device_manager.device_class.FORMATS)
|
||||||
|
files = [f for f in files if f is not None]
|
||||||
|
if not files:
|
||||||
|
dynamic.set('news_to_be_synced', set([]))
|
||||||
|
return
|
||||||
|
metadata = self.library_view.model().get_metadata(ids,
|
||||||
|
rows_are_ids=True)
|
||||||
|
names = []
|
||||||
|
for mi in metadata:
|
||||||
|
prefix = sanitize_file_name(mi['title'])
|
||||||
|
if not isinstance(prefix, unicode):
|
||||||
|
prefix = prefix.decode(preferred_encoding, 'replace')
|
||||||
|
prefix = ascii_filename(prefix)
|
||||||
|
names.append('%s_%d%s'%(prefix, id,
|
||||||
|
os.path.splitext(f.name)[1]))
|
||||||
|
cdata = mi['cover']
|
||||||
|
if cdata:
|
||||||
|
mi['cover'] = self.cover_to_thumbnail(cdata)
|
||||||
|
dynamic.set('news_to_be_synced', set([]))
|
||||||
|
if config['upload_news_to_device'] and files:
|
||||||
|
remove = ids if \
|
||||||
|
config['delete_news_from_library_on_upload'] else []
|
||||||
|
on_card = self.location_view.model().free[0] < \
|
||||||
|
self.location_view.model().free[1]
|
||||||
|
self.upload_books(files, names, metadata,
|
||||||
|
on_card=on_card,
|
||||||
|
memory=[[f.name for f in files], remove])
|
||||||
|
self.status_bar.showMessage(_('Sending news to device.'), 5000)
|
||||||
|
|
||||||
|
|
||||||
|
def sync_to_device(self, on_card, delete_from_library,
|
||||||
|
specific_format=None):
|
||||||
|
rows = self.library_view.selectionModel().selectedRows()
|
||||||
|
if not self.device_manager or not rows or len(rows) == 0:
|
||||||
|
return
|
||||||
|
ids = iter(self.library_view.model().id(r) for r in rows)
|
||||||
|
metadata = self.library_view.model().get_metadata(rows)
|
||||||
|
for mi in metadata:
|
||||||
|
cdata = mi['cover']
|
||||||
|
if cdata:
|
||||||
|
mi['cover'] = self.cover_to_thumbnail(cdata)
|
||||||
|
metadata = iter(metadata)
|
||||||
|
_files = self.library_view.model().get_preferred_formats(rows,
|
||||||
|
self.device_manager.device_class.FORMATS,
|
||||||
|
paths=True, set_metadata=True,
|
||||||
|
specific_format=specific_format)
|
||||||
|
files = [getattr(f, 'name', None) for f in _files]
|
||||||
|
bad, good, gf, names, remove_ids = [], [], [], [], []
|
||||||
|
for f in files:
|
||||||
|
mi = metadata.next()
|
||||||
|
id = ids.next()
|
||||||
|
if f is None:
|
||||||
|
bad.append(mi['title'])
|
||||||
|
else:
|
||||||
|
remove_ids.append(id)
|
||||||
|
good.append(mi)
|
||||||
|
gf.append(f)
|
||||||
|
t = mi['title']
|
||||||
|
if not t:
|
||||||
|
t = _('Unknown')
|
||||||
|
a = mi['authors']
|
||||||
|
if not a:
|
||||||
|
a = _('Unknown')
|
||||||
|
prefix = sanitize_file_name(t+' - '+a)
|
||||||
|
if not isinstance(prefix, unicode):
|
||||||
|
prefix = prefix.decode(preferred_encoding, 'replace')
|
||||||
|
prefix = ascii_filename(prefix)
|
||||||
|
names.append('%s_%d%s'%(prefix, id, os.path.splitext(f)[1]))
|
||||||
|
remove = remove_ids if delete_from_library else []
|
||||||
|
self.upload_books(gf, names, good, on_card, memory=(_files, remove))
|
||||||
|
self.status_bar.showMessage(_('Sending books to device.'), 5000)
|
||||||
|
if bad:
|
||||||
|
bad = '\n'.join('<li>%s</li>'%(i,) for i in bad)
|
||||||
|
d = warning_dialog(self, _('No suitable formats'),
|
||||||
|
_('Could not upload the following books to the device, '
|
||||||
|
'as no suitable formats were found:<br><ul>%s</ul>')%(bad,))
|
||||||
|
d.exec_()
|
||||||
|
|
||||||
|
def upload_booklists(self):
|
||||||
|
'''
|
||||||
|
Upload metadata to device.
|
||||||
|
'''
|
||||||
|
self.device_manager.sync_booklists(Dispatcher(self.metadata_synced),
|
||||||
|
self.booklists())
|
||||||
|
|
||||||
|
def metadata_synced(self, job):
|
||||||
|
'''
|
||||||
|
Called once metadata has been uploaded.
|
||||||
|
'''
|
||||||
|
if job.exception is not None:
|
||||||
|
self.device_job_exception(job)
|
||||||
|
return
|
||||||
|
cp, fs = job.result
|
||||||
|
self.location_view.model().update_devices(cp, fs)
|
||||||
|
|
||||||
|
def upload_books(self, files, names, metadata, on_card=False, memory=None):
|
||||||
|
'''
|
||||||
|
Upload books to device.
|
||||||
|
:param files: List of either paths to files or file like objects
|
||||||
|
'''
|
||||||
|
titles = [i['title'] for i in metadata]
|
||||||
|
job = self.device_manager.upload_books(
|
||||||
|
Dispatcher(self.books_uploaded),
|
||||||
|
files, names, on_card=on_card,
|
||||||
|
metadata=metadata, titles=titles
|
||||||
|
)
|
||||||
|
self.upload_memory[job] = (metadata, on_card, memory, files)
|
||||||
|
|
||||||
|
def books_uploaded(self, job):
|
||||||
|
'''
|
||||||
|
Called once books have been uploaded.
|
||||||
|
'''
|
||||||
|
metadata, on_card, memory, files = self.upload_memory.pop(job)
|
||||||
|
|
||||||
|
if job.exception is not None:
|
||||||
|
if isinstance(job.exception, FreeSpaceError):
|
||||||
|
where = 'in main memory.' if 'memory' in str(job.exception) \
|
||||||
|
else 'on the storage card.'
|
||||||
|
titles = '\n'.join(['<li>'+mi['title']+'</li>' \
|
||||||
|
for mi in metadata])
|
||||||
|
d = error_dialog(self, _('No space on device'),
|
||||||
|
_('<p>Cannot upload books to device there '
|
||||||
|
'is no more free space available ')+where+
|
||||||
|
'</p>\n<ul>%s</ul>'%(titles,))
|
||||||
|
d.exec_()
|
||||||
|
else:
|
||||||
|
self.device_job_exception(job)
|
||||||
|
return
|
||||||
|
|
||||||
|
self.device_manager.add_books_to_metadata(job.result,
|
||||||
|
metadata, self.booklists())
|
||||||
|
|
||||||
|
self.upload_booklists()
|
||||||
|
|
||||||
|
view = self.card_view if on_card else self.memory_view
|
||||||
|
view.model().resort(reset=False)
|
||||||
|
view.model().research()
|
||||||
|
for f in files:
|
||||||
|
getattr(f, 'close', lambda : True)()
|
||||||
|
if memory and memory[1]:
|
||||||
|
self.library_view.model().delete_books_by_id(memory[1])
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
import os, re, time, textwrap
|
import os, re, time, textwrap
|
||||||
|
from binascii import hexlify, unhexlify
|
||||||
|
|
||||||
from PyQt4.Qt import QDialog, QMessageBox, QListWidgetItem, QIcon, \
|
from PyQt4.Qt import QDialog, QMessageBox, QListWidgetItem, QIcon, \
|
||||||
QDesktopServices, QVBoxLayout, QLabel, QPlainTextEdit, \
|
QDesktopServices, QVBoxLayout, QLabel, QPlainTextEdit, \
|
||||||
QStringListModel, QAbstractItemModel, \
|
QStringListModel, QAbstractItemModel, QFont, \
|
||||||
SIGNAL, QTimer, Qt, QSize, QVariant, QUrl, \
|
SIGNAL, QTimer, Qt, QSize, QVariant, QUrl, \
|
||||||
QModelIndex, QInputDialog
|
QModelIndex, QInputDialog, QAbstractTableModel
|
||||||
|
|
||||||
from calibre.constants import islinux, iswindows
|
from calibre.constants import islinux, iswindows
|
||||||
from calibre.gui2.dialogs.config_ui import Ui_Dialog
|
from calibre.gui2.dialogs.config_ui import Ui_Dialog
|
||||||
@ -21,6 +22,7 @@ from calibre.library import server_config
|
|||||||
from calibre.customize.ui import initialized_plugins, is_disabled, enable_plugin, \
|
from calibre.customize.ui import initialized_plugins, is_disabled, enable_plugin, \
|
||||||
disable_plugin, customize_plugin, \
|
disable_plugin, customize_plugin, \
|
||||||
plugin_customization, add_plugin, remove_plugin
|
plugin_customization, add_plugin, remove_plugin
|
||||||
|
from calibre.utils.smtp import config as smtp_prefs
|
||||||
|
|
||||||
class PluginModel(QAbstractItemModel):
|
class PluginModel(QAbstractItemModel):
|
||||||
|
|
||||||
@ -120,12 +122,12 @@ class CategoryModel(QStringListModel):
|
|||||||
|
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
QStringListModel.__init__(self, *args)
|
QStringListModel.__init__(self, *args)
|
||||||
self.setStringList([_('General'), _('Interface'), _('Advanced'),
|
self.setStringList([_('General'), _('Interface'), _('Email\nDelivery'),
|
||||||
_('Content\nServer'), _('Plugins')])
|
_('Advanced'), _('Content\nServer'), _('Plugins')])
|
||||||
self.icons = list(map(QVariant, map(QIcon,
|
self.icons = list(map(QVariant, map(QIcon,
|
||||||
[':/images/dialog_information.svg', ':/images/lookfeel.svg',
|
[':/images/dialog_information.svg', ':/images/lookfeel.svg',
|
||||||
':/images/view.svg', ':/images/network-server.svg',
|
':/images/mail.svg', ':/images/view.svg',
|
||||||
':/images/plugins.svg'])))
|
':/images/network-server.svg', ':/images/plugins.svg'])))
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
if role == Qt.DecorationRole:
|
if role == Qt.DecorationRole:
|
||||||
@ -133,6 +135,121 @@ class CategoryModel(QStringListModel):
|
|||||||
return QStringListModel.data(self, index, role)
|
return QStringListModel.data(self, index, role)
|
||||||
|
|
||||||
|
|
||||||
|
class EmailAccounts(QAbstractTableModel):
|
||||||
|
|
||||||
|
def __init__(self, accounts):
|
||||||
|
QAbstractTableModel.__init__(self)
|
||||||
|
self.accounts = accounts
|
||||||
|
self.account_order = sorted(self.accounts.keys())
|
||||||
|
self.headers = map(QVariant, [_('Email'), _('Formats'), _('Auto send')])
|
||||||
|
self.default_font = QFont()
|
||||||
|
self.default_font.setBold(True)
|
||||||
|
self.default_font = QVariant(self.default_font)
|
||||||
|
self.tooltips =[NONE] + map(QVariant,
|
||||||
|
[_('Formats to email. The first matching format will be sent.'),
|
||||||
|
'<p>'+_('If checked, downloaded news will be automatically '
|
||||||
|
'mailed <br>to this email address '
|
||||||
|
'(provided it is in one of the listed formats).')])
|
||||||
|
|
||||||
|
def rowCount(self, *args):
|
||||||
|
return len(self.account_order)
|
||||||
|
|
||||||
|
def columnCount(self, *args):
|
||||||
|
return 3
|
||||||
|
|
||||||
|
def headerData(self, section, orientation, role):
|
||||||
|
if role == Qt.DisplayRole and orientation == Qt.Horizontal:
|
||||||
|
return self.headers[section]
|
||||||
|
return NONE
|
||||||
|
|
||||||
|
def data(self, index, role):
|
||||||
|
row, col = index.row(), index.column()
|
||||||
|
if row < 0 or row >= self.rowCount():
|
||||||
|
return NONE
|
||||||
|
account = self.account_order[row]
|
||||||
|
if role == Qt.UserRole:
|
||||||
|
return (account, self.accounts[account])
|
||||||
|
if role == Qt.ToolTipRole:
|
||||||
|
return self.tooltips[col]
|
||||||
|
if role == Qt.DisplayRole:
|
||||||
|
if col == 0:
|
||||||
|
return QVariant(account)
|
||||||
|
if col == 1:
|
||||||
|
return QVariant(self.accounts[account][0])
|
||||||
|
if role == Qt.FontRole and self.accounts[account][2]:
|
||||||
|
return self.default_font
|
||||||
|
if role == Qt.CheckStateRole and col == 2:
|
||||||
|
return QVariant(Qt.Checked if self.accounts[account][1] else Qt.Unchecked)
|
||||||
|
return NONE
|
||||||
|
|
||||||
|
def flags(self, index):
|
||||||
|
if index.column() == 2:
|
||||||
|
return QAbstractTableModel.flags(self, index)|Qt.ItemIsUserCheckable
|
||||||
|
else:
|
||||||
|
return QAbstractTableModel.flags(self, index)|Qt.ItemIsEditable
|
||||||
|
|
||||||
|
def setData(self, index, value, role):
|
||||||
|
if not index.isValid():
|
||||||
|
return False
|
||||||
|
row, col = index.row(), index.column()
|
||||||
|
account = self.account_order[row]
|
||||||
|
if col == 2:
|
||||||
|
self.accounts[account][1] ^= True
|
||||||
|
elif col == 1:
|
||||||
|
self.accounts[account][0] = unicode(value.toString()).upper()
|
||||||
|
else:
|
||||||
|
na = unicode(value.toString())
|
||||||
|
from email.utils import parseaddr
|
||||||
|
addr = parseaddr(na)[-1]
|
||||||
|
if not addr:
|
||||||
|
return False
|
||||||
|
self.accounts[na] = self.accounts.pop(account)
|
||||||
|
self.account_order[row] = na
|
||||||
|
if '@kindle.com' in addr:
|
||||||
|
self.accounts[na][0] = 'AZW, MOBI, TPZ, PRC, AZW1'
|
||||||
|
|
||||||
|
self.emit(SIGNAL('dataChanged(QModelIndex,QModelIndex)'),
|
||||||
|
self.index(index.row(), 0), self.index(index.row(), 2))
|
||||||
|
return True
|
||||||
|
|
||||||
|
def make_default(self, index):
|
||||||
|
if index.isValid():
|
||||||
|
row = index.row()
|
||||||
|
for x in self.accounts.values():
|
||||||
|
x[2] = False
|
||||||
|
self.accounts[self.account_order[row]][2] = True
|
||||||
|
self.reset()
|
||||||
|
|
||||||
|
def add(self):
|
||||||
|
x = _('new email address')
|
||||||
|
y = x
|
||||||
|
c = 0
|
||||||
|
while y in self.accounts:
|
||||||
|
c += 1
|
||||||
|
y = x + str(c)
|
||||||
|
self.accounts[y] = ['MOBI, EPUB', True,
|
||||||
|
len(self.account_order) == 0]
|
||||||
|
self.account_order = sorted(self.accounts.keys())
|
||||||
|
self.reset()
|
||||||
|
return self.index(self.account_order.index(y), 0)
|
||||||
|
|
||||||
|
def remove(self, index):
|
||||||
|
if index.isValid():
|
||||||
|
row = self.index.row()
|
||||||
|
account = self.account_order[row]
|
||||||
|
self.accounts.pop(account)
|
||||||
|
self.account_order = sorted(self.accounts.keys())
|
||||||
|
has_default = False
|
||||||
|
for account in self.account_order:
|
||||||
|
if self.accounts[account][2]:
|
||||||
|
has_default = True
|
||||||
|
break
|
||||||
|
if not has_default and self.account_order:
|
||||||
|
self.accounts[self.account_order[0]][2] = True
|
||||||
|
|
||||||
|
self.reset()
|
||||||
|
|
||||||
|
|
||||||
class ConfigDialog(QDialog, Ui_Dialog):
|
class ConfigDialog(QDialog, Ui_Dialog):
|
||||||
|
|
||||||
def __init__(self, window, db, server=None):
|
def __init__(self, window, db, server=None):
|
||||||
@ -142,8 +259,8 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
self._category_model = CategoryModel()
|
self._category_model = CategoryModel()
|
||||||
|
|
||||||
self.connect(self.category_view, SIGNAL('activated(QModelIndex)'), lambda i: self.stackedWidget.setCurrentIndex(i.row()))
|
self.category_view.currentChanged = \
|
||||||
self.connect(self.category_view, SIGNAL('clicked(QModelIndex)'), lambda i: self.stackedWidget.setCurrentIndex(i.row()))
|
lambda n, p: self.stackedWidget.setCurrentIndex(n.row())
|
||||||
self.category_view.setModel(self._category_model)
|
self.category_view.setModel(self._category_model)
|
||||||
self.db = db
|
self.db = db
|
||||||
self.server = server
|
self.server = server
|
||||||
@ -242,7 +359,6 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
self.priority.setCurrentIndex(p)
|
self.priority.setCurrentIndex(p)
|
||||||
self.priority.setVisible(iswindows)
|
self.priority.setVisible(iswindows)
|
||||||
self.priority_label.setVisible(iswindows)
|
self.priority_label.setVisible(iswindows)
|
||||||
self.category_view.setCurrentIndex(self._category_model.index(0))
|
|
||||||
self._plugin_model = PluginModel()
|
self._plugin_model = PluginModel()
|
||||||
self.plugin_view.setModel(self._plugin_model)
|
self.plugin_view.setModel(self._plugin_model)
|
||||||
self.connect(self.toggle_plugin, SIGNAL('clicked()'), lambda : self.modify_plugin(op='toggle'))
|
self.connect(self.toggle_plugin, SIGNAL('clicked()'), lambda : self.modify_plugin(op='toggle'))
|
||||||
@ -251,6 +367,74 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
self.connect(self.button_plugin_browse, SIGNAL('clicked()'), self.find_plugin)
|
self.connect(self.button_plugin_browse, SIGNAL('clicked()'), self.find_plugin)
|
||||||
self.connect(self.button_plugin_add, SIGNAL('clicked()'), self.add_plugin)
|
self.connect(self.button_plugin_add, SIGNAL('clicked()'), self.add_plugin)
|
||||||
self.separate_cover_flow.setChecked(config['separate_cover_flow'])
|
self.separate_cover_flow.setChecked(config['separate_cover_flow'])
|
||||||
|
self.setup_email_page()
|
||||||
|
self.category_view.setCurrentIndex(self.category_view.model().index(0))
|
||||||
|
|
||||||
|
def setup_email_page(self):
|
||||||
|
opts = smtp_prefs().parse()
|
||||||
|
if opts.from_:
|
||||||
|
self.email_from.setText(opts.from_)
|
||||||
|
self._email_accounts = EmailAccounts(opts.accounts)
|
||||||
|
self.email_view.setModel(self._email_accounts)
|
||||||
|
if opts.relay_host:
|
||||||
|
self.relay_host.setText(opts.relay_host)
|
||||||
|
self.relay_port.setValue(opts.relay_port)
|
||||||
|
if opts.relay_username:
|
||||||
|
self.relay_username.setText(opts.relay_username)
|
||||||
|
if opts.relay_password:
|
||||||
|
self.relay_password.setText(unhexlify(opts.relay_password))
|
||||||
|
(self.relay_tls if opts.encryption == 'TLS' else self.relay_ssl).setChecked(True)
|
||||||
|
self.connect(self.relay_use_gmail, SIGNAL('clicked(bool)'),
|
||||||
|
self.create_gmail_relay)
|
||||||
|
self.connect(self.relay_show_password, SIGNAL('stateChanged(int)'),
|
||||||
|
lambda state:self.relay_password.setEchoMode(self.relay_password.Password))
|
||||||
|
self.connect(self.email_add, SIGNAL('clicked(bool)'),
|
||||||
|
self.add_email_account)
|
||||||
|
self.connect(self.email_make_default, SIGNAL('clicked(bool)'),
|
||||||
|
lambda c: self._email_accounts.make_default(self.email_view.currentIndex()))
|
||||||
|
self.email_view.resizeColumnsToContents()
|
||||||
|
|
||||||
|
def add_email_account(self, checked):
|
||||||
|
index = self._email_accounts.add()
|
||||||
|
self.email_view.setCurrentIndex(index)
|
||||||
|
self.email_view.resizeColumnsToContents()
|
||||||
|
self.email_view.edit(index)
|
||||||
|
|
||||||
|
def create_gmail_relay(self, *args):
|
||||||
|
self.relay_username.setText('@gmail.com')
|
||||||
|
self.relay_password.setText('')
|
||||||
|
self.relay_host.setText('smtp.gmail.com')
|
||||||
|
self.relay_port.setValue(587)
|
||||||
|
self.relay_tls.setChecked(True)
|
||||||
|
|
||||||
|
info_dialog(self, _('Finish gmail setup'),
|
||||||
|
_('Dont forget to enter your gmail username and password')).exec_()
|
||||||
|
self.relay_username.setFocus(Qt.OtherFocusReason)
|
||||||
|
self.relay_username.setCursorPosition(0)
|
||||||
|
|
||||||
|
def set_email_settings(self):
|
||||||
|
from_ = unicode(self.email_from.text()).strip()
|
||||||
|
if self._email_accounts.accounts and not from_:
|
||||||
|
error_dialog(self, _('Bad configuration'),
|
||||||
|
_('You must set the From email address')).exec_()
|
||||||
|
return False
|
||||||
|
username = unicode(self.relay_username.text()).strip()
|
||||||
|
password = unicode(self.relay_password.text()).strip()
|
||||||
|
host = unicode(self.relay_host.text()).strip()
|
||||||
|
if host and not (username and password):
|
||||||
|
error_dialog(self, _('Bad configuration'),
|
||||||
|
_('You must set the username and password for '
|
||||||
|
'the mail server.')).exec_()
|
||||||
|
return False
|
||||||
|
conf = smtp_prefs()
|
||||||
|
conf.set('from_', from_)
|
||||||
|
conf.set('accounts', self._email_accounts.accounts)
|
||||||
|
conf.set('relay_host', host if host else None)
|
||||||
|
conf.set('relay_port', self.relay_port.value())
|
||||||
|
conf.set('relay_username', username if username else None)
|
||||||
|
conf.set('relay_password', hexlify(password))
|
||||||
|
conf.set('encryption', 'TLS' if self.relay_tls.isChecked() else 'SSL')
|
||||||
|
return True
|
||||||
|
|
||||||
def add_plugin(self):
|
def add_plugin(self):
|
||||||
path = unicode(self.plugin_path.text())
|
path = unicode(self.plugin_path.text())
|
||||||
@ -300,7 +484,8 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
self._plugin_model.reset()
|
self._plugin_model.reset()
|
||||||
else:
|
else:
|
||||||
error_dialog(self, _('Cannot remove builtin plugin'),
|
error_dialog(self, _('Cannot remove builtin plugin'),
|
||||||
plugin.name + _(' cannot be removed. It is a builtin plugin. Try disabling it instead.')).exec_()
|
plugin.name + _(' cannot be removed. It is a '
|
||||||
|
'builtin plugin. Try disabling it instead.')).exec_()
|
||||||
|
|
||||||
|
|
||||||
def up_column(self):
|
def up_column(self):
|
||||||
@ -376,7 +561,8 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
d.exec_()
|
d.exec_()
|
||||||
|
|
||||||
def browse(self):
|
def browse(self):
|
||||||
dir = choose_dir(self, 'database location dialog', 'Select database location')
|
dir = choose_dir(self, 'database location dialog',
|
||||||
|
_('Select database location'))
|
||||||
if dir:
|
if dir:
|
||||||
self.location.setText(dir)
|
self.location.setText(dir)
|
||||||
|
|
||||||
@ -393,7 +579,10 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
def accept(self):
|
def accept(self):
|
||||||
mcs = unicode(self.max_cover_size.text()).strip()
|
mcs = unicode(self.max_cover_size.text()).strip()
|
||||||
if not re.match(r'\d+x\d+', mcs):
|
if not re.match(r'\d+x\d+', mcs):
|
||||||
error_dialog(self, _('Invalid size'), _('The size %s is invalid. must be of the form widthxheight')%mcs).exec_()
|
error_dialog(self, _('Invalid size'),
|
||||||
|
_('The size %s is invalid. must be of the form widthxheight')%mcs).exec_()
|
||||||
|
return
|
||||||
|
if not self.set_email_settings():
|
||||||
return
|
return
|
||||||
config['use_roman_numerals_for_series_number'] = bool(self.roman_numerals.isChecked())
|
config['use_roman_numerals_for_series_number'] = bool(self.roman_numerals.isChecked())
|
||||||
config['new_version_notification'] = bool(self.new_version_notification.isChecked())
|
config['new_version_notification'] = bool(self.new_version_notification.isChecked())
|
||||||
@ -432,7 +621,8 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
|
|
||||||
if not path or not os.path.exists(path) or not os.path.isdir(path):
|
if not path or not os.path.exists(path) or not os.path.isdir(path):
|
||||||
d = error_dialog(self, _('Invalid database location'),
|
d = error_dialog(self, _('Invalid database location'),
|
||||||
_('Invalid database location ')+path+_('<br>Must be a directory.'))
|
_('Invalid database location ')+path+
|
||||||
|
_('<br>Must be a directory.'))
|
||||||
d.exec_()
|
d.exec_()
|
||||||
elif not os.access(path, os.W_OK):
|
elif not os.access(path, os.W_OK):
|
||||||
d = error_dialog(self, _('Invalid database location'),
|
d = error_dialog(self, _('Invalid database location'),
|
||||||
@ -440,7 +630,9 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
d.exec_()
|
d.exec_()
|
||||||
else:
|
else:
|
||||||
self.database_location = os.path.abspath(path)
|
self.database_location = os.path.abspath(path)
|
||||||
self.directories = [qstring_to_unicode(self.directory_list.item(i).text()) for i in range(self.directory_list.count())]
|
self.directories = [
|
||||||
|
qstring_to_unicode(self.directory_list.item(i).text()) for i in \
|
||||||
|
range(self.directory_list.count())]
|
||||||
config['frequently_used_directories'] = self.directories
|
config['frequently_used_directories'] = self.directories
|
||||||
QDialog.accept(self)
|
QDialog.accept(self)
|
||||||
|
|
||||||
@ -448,7 +640,8 @@ class Vacuum(QMessageBox):
|
|||||||
|
|
||||||
def __init__(self, parent, db):
|
def __init__(self, parent, db):
|
||||||
self.db = db
|
self.db = db
|
||||||
QMessageBox.__init__(self, QMessageBox.Information, _('Compacting...'), _('Compacting database. This may take a while.'),
|
QMessageBox.__init__(self, QMessageBox.Information, _('Compacting...'),
|
||||||
|
_('Compacting database. This may take a while.'),
|
||||||
QMessageBox.NoButton, parent)
|
QMessageBox.NoButton, parent)
|
||||||
QTimer.singleShot(200, self.vacuum)
|
QTimer.singleShot(200, self.vacuum)
|
||||||
|
|
||||||
@ -456,3 +649,11 @@ class Vacuum(QMessageBox):
|
|||||||
self.db.vacuum()
|
self.db.vacuum()
|
||||||
self.accept()
|
self.accept()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from calibre.library.database2 import LibraryDatabase2
|
||||||
|
from PyQt4.Qt import QApplication
|
||||||
|
app = QApplication([])
|
||||||
|
d=ConfigDialog(None, LibraryDatabase2('/tmp'))
|
||||||
|
d.category_view.setCurrentIndex(d.category_view.model().index(2))
|
||||||
|
d.show()
|
||||||
|
app.exec_()
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>755</width>
|
<width>789</width>
|
||||||
<height>557</height>
|
<height>557</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -437,12 +437,6 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
<zorder>toolbar_button_size</zorder>
|
|
||||||
<zorder>label_4</zorder>
|
|
||||||
<zorder>show_toolbar_text</zorder>
|
|
||||||
<zorder>columns</zorder>
|
|
||||||
<zorder></zorder>
|
|
||||||
<zorder>groupBox_3</zorder>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -507,7 +501,6 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
<zorder>columns</zorder>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@ -534,16 +527,287 @@
|
|||||||
</layout>
|
</layout>
|
||||||
<zorder>roman_numerals</zorder>
|
<zorder>roman_numerals</zorder>
|
||||||
<zorder>groupBox_2</zorder>
|
<zorder>groupBox_2</zorder>
|
||||||
<zorder>groupBox</zorder>
|
|
||||||
<zorder>systray_icon</zorder>
|
<zorder>systray_icon</zorder>
|
||||||
<zorder>sync_news</zorder>
|
<zorder>sync_news</zorder>
|
||||||
<zorder>delete_news</zorder>
|
<zorder>delete_news</zorder>
|
||||||
<zorder>separate_cover_flow</zorder>
|
<zorder>separate_cover_flow</zorder>
|
||||||
<zorder>systray_notifications</zorder>
|
<zorder>systray_notifications</zorder>
|
||||||
<zorder>groupBox_3</zorder>
|
|
||||||
<zorder></zorder>
|
<zorder></zorder>
|
||||||
<zorder></zorder>
|
<zorder></zorder>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QWidget" name="page_6" >
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_9" >
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_22" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>calibre can send your books to you (or your reader) by email</string>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_9" >
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_15" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Send email &from:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy" >
|
||||||
|
<cstring>email_from</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="email_from" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string><p>This is what will be present in the From: field of emails sent by calibre.<br> Set it to your email address</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_8" >
|
||||||
|
<item>
|
||||||
|
<widget class="QTableView" name="email_view" >
|
||||||
|
<property name="selectionMode" >
|
||||||
|
<enum>QAbstractItemView::SingleSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="selectionBehavior" >
|
||||||
|
<enum>QAbstractItemView::SelectRows</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_8" >
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="email_add" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>Add an email address to which to send books</string>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>&Add email</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset resource="../images.qrc" >
|
||||||
|
<normaloff>:/images/plus.svg</normaloff>:/images/plus.svg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="iconSize" >
|
||||||
|
<size>
|
||||||
|
<width>24</width>
|
||||||
|
<height>24</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="toolButtonStyle" >
|
||||||
|
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="email_make_default" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Make &default</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="email_remove" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>&Remove email</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset resource="../images.qrc" >
|
||||||
|
<normaloff>:/images/minus.svg</normaloff>:/images/minus.svg</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="iconSize" >
|
||||||
|
<size>
|
||||||
|
<width>24</width>
|
||||||
|
<height>24</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="toolButtonStyle" >
|
||||||
|
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_10" >
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox_5" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string><p>A mail server is useful if the service you are sending mail to only accepts email from well know mail services.</string>
|
||||||
|
</property>
|
||||||
|
<property name="title" >
|
||||||
|
<string>Mail &Server</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_3" >
|
||||||
|
<item row="0" column="0" colspan="4" >
|
||||||
|
<widget class="QLabel" name="label_16" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>calibre can <b>optionally</b> use a server to send mail</string>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" >
|
||||||
|
<widget class="QLabel" name="label_17" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>&Hostname:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy" >
|
||||||
|
<cstring>relay_host</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1" colspan="2" >
|
||||||
|
<widget class="QLineEdit" name="relay_host" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>The hostname if your mail server. For e.g. smtp.gmail.com</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="3" >
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_11" >
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_18" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>&Port:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy" >
|
||||||
|
<cstring>relay_port</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="relay_port" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>The port your mail server listens for connections on. The default is 25</string>
|
||||||
|
</property>
|
||||||
|
<property name="minimum" >
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum" >
|
||||||
|
<number>65555</number>
|
||||||
|
</property>
|
||||||
|
<property name="value" >
|
||||||
|
<number>25</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0" >
|
||||||
|
<widget class="QLabel" name="label_19" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>&Username:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy" >
|
||||||
|
<cstring>relay_username</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1" colspan="2" >
|
||||||
|
<widget class="QLineEdit" name="relay_username" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>Your username on the mail server</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0" >
|
||||||
|
<widget class="QLabel" name="label_20" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>&Password:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy" >
|
||||||
|
<cstring>relay_password</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="1" colspan="2" >
|
||||||
|
<widget class="QLineEdit" name="relay_password" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>Your password on the mail server</string>
|
||||||
|
</property>
|
||||||
|
<property name="echoMode" >
|
||||||
|
<enum>QLineEdit::Password</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="3" >
|
||||||
|
<widget class="QCheckBox" name="relay_show_password" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>&Show</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0" >
|
||||||
|
<widget class="QLabel" name="label_21" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>&Encryption:</string>
|
||||||
|
</property>
|
||||||
|
<property name="buddy" >
|
||||||
|
<cstring>relay_tls</cstring>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1" >
|
||||||
|
<widget class="QRadioButton" name="relay_tls" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>Use TLS encryption when connecting to the mail server. This is the most common.</string>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>&TLS</string>
|
||||||
|
</property>
|
||||||
|
<property name="checked" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="2" colspan="2" >
|
||||||
|
<widget class="QRadioButton" name="relay_ssl" >
|
||||||
|
<property name="toolTip" >
|
||||||
|
<string>Use SSL encryption when connecting to the mail server.</string>
|
||||||
|
</property>
|
||||||
|
<property name="text" >
|
||||||
|
<string>&SSL</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="relay_use_gmail" >
|
||||||
|
<property name="text" >
|
||||||
|
<string>Use Gmail</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon" >
|
||||||
|
<iconset resource="../images.qrc" >
|
||||||
|
<normaloff>:/images/gmail_logo.png</normaloff>:/images/gmail_logo.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="iconSize" >
|
||||||
|
<size>
|
||||||
|
<width>48</width>
|
||||||
|
<height>48</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="toolButtonStyle" >
|
||||||
|
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
<widget class="QWidget" name="page_2" >
|
<widget class="QWidget" name="page_2" >
|
||||||
<layout class="QVBoxLayout" >
|
<layout class="QVBoxLayout" >
|
||||||
<item>
|
<item>
|
||||||
|
@ -104,14 +104,15 @@ class FetchMetadata(QDialog, Ui_FetchMetadata):
|
|||||||
self.author = author.strip()
|
self.author = author.strip()
|
||||||
self.publisher = publisher
|
self.publisher = publisher
|
||||||
self.previous_row = None
|
self.previous_row = None
|
||||||
|
self.warning.setVisible(False)
|
||||||
self.connect(self.matches, SIGNAL('activated(QModelIndex)'), self.chosen)
|
self.connect(self.matches, SIGNAL('activated(QModelIndex)'), self.chosen)
|
||||||
self.connect(self.matches, SIGNAL('entered(QModelIndex)'),
|
self.connect(self.matches, SIGNAL('entered(QModelIndex)'),
|
||||||
lambda index:self.matches.setCurrentIndex(index))
|
self.show_summary)
|
||||||
self.matches.setMouseTracking(True)
|
self.matches.setMouseTracking(True)
|
||||||
self.fetch_metadata()
|
self.fetch_metadata()
|
||||||
|
|
||||||
|
|
||||||
def show_summary(self, current, previous):
|
def show_summary(self, current, *args):
|
||||||
row = current.row()
|
row = current.row()
|
||||||
if row != self.previous_row:
|
if row != self.previous_row:
|
||||||
summ = self.model.summary(row)
|
summ = self.model.summary(row)
|
||||||
@ -119,6 +120,7 @@ class FetchMetadata(QDialog, Ui_FetchMetadata):
|
|||||||
self.previous_row = row
|
self.previous_row = row
|
||||||
|
|
||||||
def fetch_metadata(self):
|
def fetch_metadata(self):
|
||||||
|
self.warning.setVisible(False)
|
||||||
key = str(self.key.text())
|
key = str(self.key.text())
|
||||||
if key:
|
if key:
|
||||||
prefs['isbndb_com_key'] = key
|
prefs['isbndb_com_key'] = key
|
||||||
@ -158,14 +160,14 @@ class FetchMetadata(QDialog, Ui_FetchMetadata):
|
|||||||
self.fetcher.exceptions if x[1] is not None]
|
self.fetcher.exceptions if x[1] is not None]
|
||||||
if warnings:
|
if warnings:
|
||||||
warnings='<br>'.join(['<b>%s</b>: %s'%(name, exc) for name,exc in warnings])
|
warnings='<br>'.join(['<b>%s</b>: %s'%(name, exc) for name,exc in warnings])
|
||||||
warning_dialog(self, _('Warning'),
|
self.warning.setText('<p><b>'+ _('Warning')+':</b>'+\
|
||||||
'<p>'+_('Could not fetch metadata from:')+\
|
_('Could not fetch metadata from:')+\
|
||||||
'<br><br>'+warnings+'</p>').exec_()
|
'<br>'+warnings+'</p>')
|
||||||
|
self.warning.setVisible(True)
|
||||||
if self.model.rowCount() < 1:
|
if self.model.rowCount() < 1:
|
||||||
info_dialog(self, _('No metadata found'),
|
info_dialog(self, _('No metadata found'),
|
||||||
_('No metadata found, try adjusting the title and author '
|
_('No metadata found, try adjusting the title and author '
|
||||||
'or the ISBN key.')).exec_()
|
'or the ISBN key.')).exec_()
|
||||||
self.reject()
|
|
||||||
return
|
return
|
||||||
|
|
||||||
self.matches.setModel(self.model)
|
self.matches.setModel(self.model)
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="tlabel" >
|
<widget class="QLabel" name="tlabel" >
|
||||||
<property name="text" >
|
<property name="text" >
|
||||||
<string><p>calibre can find metadata for your books from two locations: <b>Google Books</b> and <b>isbndb.com</b>. <p>To use isbndb.com you must sign up for a <a href="http://www.isbndb.com">free account</a> and exter you access key below.</string>
|
<string><p>calibre can find metadata for your books from two locations: <b>Google Books</b> and <b>isbndb.com</b>. <p>To use isbndb.com you must sign up for a <a href="http://www.isbndb.com">free account</a> and enter your access key below.</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="alignment" >
|
<property name="alignment" >
|
||||||
<set>Qt::AlignCenter</set>
|
<set>Qt::AlignCenter</set>
|
||||||
@ -60,6 +60,16 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="warning" >
|
||||||
|
<property name="text" >
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap" >
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox" >
|
<widget class="QGroupBox" name="groupBox" >
|
||||||
<property name="title" >
|
<property name="title" >
|
||||||
|
@ -428,7 +428,9 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
prefix += '\n'
|
prefix += '\n'
|
||||||
self.comments.setText(prefix + summ)
|
self.comments.setText(prefix + summ)
|
||||||
else:
|
else:
|
||||||
error_dialog(self, 'Cannot fetch metadata', 'You must specify at least one of ISBN, Title, Authors or Publisher')
|
error_dialog(self, _('Cannot fetch metadata'),
|
||||||
|
_('You must specify at least one of ISBN, Title, '
|
||||||
|
'Authors or Publisher'))
|
||||||
|
|
||||||
def enable_series_index(self, *args):
|
def enable_series_index(self, *args):
|
||||||
self.series_index.setEnabled(True)
|
self.series_index.setEnabled(True)
|
||||||
|
BIN
src/calibre/gui2/images/gmail_logo.png
Normal file
BIN
src/calibre/gui2/images/gmail_logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
270
src/calibre/gui2/images/mail.svg
Normal file
270
src/calibre/gui2/images/mail.svg
Normal file
@ -0,0 +1,270 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
<svg
|
||||||
|
xmlns:i="http://ns.adobe.com/AdobeIllustrator/10.0/"
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://web.resource.org/cc/"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="128"
|
||||||
|
height="128"
|
||||||
|
id="svg3007"
|
||||||
|
sodipodi:version="0.32"
|
||||||
|
inkscape:version="0.45.1"
|
||||||
|
version="1.0"
|
||||||
|
sodipodi:docbase="/home/david/Documents/Projects/KDE/Oxygen/kdelibs/scalable/actions"
|
||||||
|
sodipodi:docname="mail.svgz"
|
||||||
|
inkscape:output_extension="org.inkscape.output.svgz.inkscape"
|
||||||
|
inkscape:export-filename="/home/david/Documents/Projects/KDE/Oxygen/kdelibs/scalable/actions/mail.png"
|
||||||
|
inkscape:export-xdpi="90"
|
||||||
|
inkscape:export-ydpi="90">
|
||||||
|
<defs
|
||||||
|
id="defs3009">
|
||||||
|
<linearGradient
|
||||||
|
id="polygon3293_1_"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
x1="615.5"
|
||||||
|
y1="-584.6021"
|
||||||
|
x2="615.5"
|
||||||
|
y2="-595.8521"
|
||||||
|
gradientTransform="matrix(4,0,0,-4,-2402,-2314.406)">
|
||||||
|
<stop
|
||||||
|
offset="0"
|
||||||
|
style="stop-color:#6193CF"
|
||||||
|
id="stop2997" />
|
||||||
|
<stop
|
||||||
|
offset="1"
|
||||||
|
style="stop-color:#EEEEEE"
|
||||||
|
id="stop2999" />
|
||||||
|
</linearGradient>
|
||||||
|
<linearGradient
|
||||||
|
id="polygon3286_1_"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
x1="615.5"
|
||||||
|
y1="-589.8511"
|
||||||
|
x2="615.5"
|
||||||
|
y2="-580.6011"
|
||||||
|
gradientTransform="matrix(4,0,0,-4,-2402,-2314.406)">
|
||||||
|
<stop
|
||||||
|
offset="0"
|
||||||
|
style="stop-color:#6193CF"
|
||||||
|
id="stop2991" />
|
||||||
|
<stop
|
||||||
|
offset="1"
|
||||||
|
style="stop-color:#D1DFF1"
|
||||||
|
id="stop2993" />
|
||||||
|
</linearGradient>
|
||||||
|
<linearGradient
|
||||||
|
id="rect3244_1_"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
x1="59.9995"
|
||||||
|
y1="4"
|
||||||
|
x2="59.9995"
|
||||||
|
y2="72.0005"
|
||||||
|
gradientTransform="matrix(1,0,0,1.0588235,0,-0.2352941)">
|
||||||
|
<stop
|
||||||
|
offset="0"
|
||||||
|
style="stop-color:#A4C0E4"
|
||||||
|
id="stop2983" />
|
||||||
|
<stop
|
||||||
|
offset="0.25"
|
||||||
|
style="stop-color:#D1DFF1"
|
||||||
|
id="stop2985" />
|
||||||
|
<stop
|
||||||
|
offset="0.85"
|
||||||
|
style="stop-color:#FFFFFF"
|
||||||
|
id="stop2987" />
|
||||||
|
</linearGradient>
|
||||||
|
<linearGradient
|
||||||
|
inkscape:collect="always"
|
||||||
|
xlink:href="#rect3244_1_"
|
||||||
|
id="linearGradient2212"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
gradientTransform="matrix(1,0,0,1.0588235,0,-0.2352941)"
|
||||||
|
x1="59.9995"
|
||||||
|
y1="4"
|
||||||
|
x2="59.9995"
|
||||||
|
y2="72.0005" />
|
||||||
|
<linearGradient
|
||||||
|
inkscape:collect="always"
|
||||||
|
xlink:href="#polygon3286_1_"
|
||||||
|
id="linearGradient2214"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
gradientTransform="matrix(4,0,0,-4,-2402,-2314.406)"
|
||||||
|
x1="615.5"
|
||||||
|
y1="-589.8511"
|
||||||
|
x2="615.5"
|
||||||
|
y2="-580.6011" />
|
||||||
|
<linearGradient
|
||||||
|
inkscape:collect="always"
|
||||||
|
xlink:href="#polygon3293_1_"
|
||||||
|
id="linearGradient2216"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
gradientTransform="matrix(4,0,0,-4,-2402,-2314.406)"
|
||||||
|
x1="615.5"
|
||||||
|
y1="-584.6021"
|
||||||
|
x2="615.5"
|
||||||
|
y2="-595.8521" />
|
||||||
|
</defs>
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
gridtolerance="10000"
|
||||||
|
guidetolerance="10"
|
||||||
|
objecttolerance="10"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="1"
|
||||||
|
inkscape:cx="64"
|
||||||
|
inkscape:cy="64"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
inkscape:current-layer="g2972"
|
||||||
|
width="128px"
|
||||||
|
height="128px"
|
||||||
|
inkscape:showpageshadow="false"
|
||||||
|
inkscape:window-width="794"
|
||||||
|
inkscape:window-height="731"
|
||||||
|
inkscape:window-x="0"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
showgrid="true"
|
||||||
|
gridspacingx="4px"
|
||||||
|
gridspacingy="4px"
|
||||||
|
gridempspacing="2"
|
||||||
|
showborder="false" />
|
||||||
|
<metadata
|
||||||
|
id="metadata3012">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1">
|
||||||
|
<switch
|
||||||
|
id="switch2966"
|
||||||
|
transform="translate(4,12)">
|
||||||
|
<foreignObject
|
||||||
|
requiredExtensions="http://ns.adobe.com/AdobeIllustrator/10.0/"
|
||||||
|
x="0"
|
||||||
|
y="0"
|
||||||
|
width="1"
|
||||||
|
height="1"
|
||||||
|
id="foreignObject2968">
|
||||||
|
<i:pgfRef
|
||||||
|
xlink:href="#adobe_illustrator_pgf" />
|
||||||
|
</foreignObject>
|
||||||
|
<g
|
||||||
|
i:extraneous="self"
|
||||||
|
id="g2970">
|
||||||
|
<g
|
||||||
|
id="g2972">
|
||||||
|
<linearGradient
|
||||||
|
id="linearGradient3033"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
x1="59.9995"
|
||||||
|
y1="4"
|
||||||
|
x2="59.9995"
|
||||||
|
y2="72.000504">
|
||||||
|
<stop
|
||||||
|
offset="0"
|
||||||
|
style="stop-color:#A4C0E4"
|
||||||
|
id="stop3035" />
|
||||||
|
<stop
|
||||||
|
offset="0.25"
|
||||||
|
style="stop-color:#D1DFF1"
|
||||||
|
id="stop3037" />
|
||||||
|
<stop
|
||||||
|
offset="0.85"
|
||||||
|
style="stop-color:#FFFFFF"
|
||||||
|
id="stop3039" />
|
||||||
|
</linearGradient>
|
||||||
|
<linearGradient
|
||||||
|
id="linearGradient3042"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
x1="615.5"
|
||||||
|
y1="-589.85107"
|
||||||
|
x2="615.5"
|
||||||
|
y2="-580.60107"
|
||||||
|
gradientTransform="matrix(4,0,0,-4,-2402,-2314.406)">
|
||||||
|
<stop
|
||||||
|
offset="0"
|
||||||
|
style="stop-color:#6193CF"
|
||||||
|
id="stop3044" />
|
||||||
|
<stop
|
||||||
|
offset="1"
|
||||||
|
style="stop-color:#D1DFF1"
|
||||||
|
id="stop3046" />
|
||||||
|
</linearGradient>
|
||||||
|
<linearGradient
|
||||||
|
id="linearGradient3049"
|
||||||
|
gradientUnits="userSpaceOnUse"
|
||||||
|
x1="615.5"
|
||||||
|
y1="-584.60211"
|
||||||
|
x2="615.5"
|
||||||
|
y2="-595.85211"
|
||||||
|
gradientTransform="matrix(4,0,0,-4,-2402,-2314.406)">
|
||||||
|
<stop
|
||||||
|
offset="0"
|
||||||
|
style="stop-color:#6193CF"
|
||||||
|
id="stop3051" />
|
||||||
|
<stop
|
||||||
|
offset="1"
|
||||||
|
style="stop-color:#EEEEEE"
|
||||||
|
id="stop3053" />
|
||||||
|
</linearGradient>
|
||||||
|
<g
|
||||||
|
id="g2202"
|
||||||
|
transform="translate(0,8)">
|
||||||
|
<path
|
||||||
|
style="opacity:0.1"
|
||||||
|
id="path2974"
|
||||||
|
d="M 4,0 C 1.794,0 0,1.8884211 0,4.2105263 L 0,75.789474 C 0,78.111579 1.794,80 4,80 L 116,80 C 118.206,80 120,78.111579 120,75.789474 L 120,4.2105263 C 120,1.8884211 118.206,0 116,0 L 4,0 z " />
|
||||||
|
<path
|
||||||
|
style="opacity:0.15"
|
||||||
|
id="path2976"
|
||||||
|
d="M 4,1 C 2.346,1 1,2.4187568 1,4.1621622 L 1,75.837838 C 1,77.581243 2.346,79 4,79 L 116,79 C 117.654,79 119,77.581243 119,75.837838 L 119,4.1621622 C 119,2.4187568 117.654,1 116,1 L 4,1 z " />
|
||||||
|
<path
|
||||||
|
style="opacity:0.2"
|
||||||
|
id="path2978"
|
||||||
|
d="M 4,2 C 2.897,2 2,2.9468333 2,4.1111111 L 2,75.888889 C 2,77.053167 2.897,78 4,78 L 116,78 C 117.103,78 118,77.053167 118,75.888889 L 118,4.1111111 C 118,2.9468333 117.103,2 116,2 L 4,2 z " />
|
||||||
|
<path
|
||||||
|
style="opacity:0.25"
|
||||||
|
id="path2980"
|
||||||
|
d="M 4,3 C 3.448,3 3,3.4736 3,4.0571428 L 3,75.942857 C 3,76.527457 3.448,77 4,77 L 116,77 C 116.553,77 117,76.527457 117,75.942857 L 117,4.0571428 C 117,3.4736 116.553,3 116,3 L 4,3 z " />
|
||||||
|
<rect
|
||||||
|
style="fill:url(#linearGradient2212)"
|
||||||
|
height="72"
|
||||||
|
width="112"
|
||||||
|
y="4"
|
||||||
|
x="4"
|
||||||
|
id="rect3244_9_" />
|
||||||
|
<polygon
|
||||||
|
style="fill:url(#linearGradient2214)"
|
||||||
|
points="4,8 4,12 60,45 116,12 116,8 60,41 4,8 "
|
||||||
|
id="polygon3286_9_" />
|
||||||
|
<polygon
|
||||||
|
style="fill:url(#linearGradient2216)"
|
||||||
|
points="116,69 116,65 59.997,24 4,65 4,69 59.997,28 116,69 "
|
||||||
|
id="polygon3293_9_" />
|
||||||
|
<polygon
|
||||||
|
style="fill:#ffffff"
|
||||||
|
id="polygon3002"
|
||||||
|
points="4,8 60.004,40.967 116,8 116,4 4,4 4,8 " />
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</switch>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 8.4 KiB |
@ -94,7 +94,7 @@ class DateDelegate(QStyledItemDelegate):
|
|||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
qde = QStyledItemDelegate.createEditor(self, parent, option, index)
|
qde = QStyledItemDelegate.createEditor(self, parent, option, index)
|
||||||
qde.setDisplayFormat('MM/dd/yyyy')
|
qde.setDisplayFormat('MM/dd/yyyy')
|
||||||
qde.setMinimumDate(QDate(-4000,1,1))
|
qde.setMinimumDate(QDate(101,1,1))
|
||||||
qde.setCalendarPopup(True)
|
qde.setCalendarPopup(True)
|
||||||
return qde
|
return qde
|
||||||
|
|
||||||
@ -957,7 +957,7 @@ class DeviceBooksModel(BooksModel):
|
|||||||
return QVariant('Marked for deletion')
|
return QVariant('Marked for deletion')
|
||||||
col = index.column()
|
col = index.column()
|
||||||
if col in [0, 1] or (col == 4 and self.db.supports_tags()):
|
if col in [0, 1] or (col == 4 and self.db.supports_tags()):
|
||||||
return QVariant("Double click to <b>edit</b> me<br><br>")
|
return QVariant(_("Double click to <b>edit</b> me<br><br>"))
|
||||||
return NONE
|
return NONE
|
||||||
|
|
||||||
def headerData(self, section, orientation, role):
|
def headerData(self, section, orientation, role):
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,3 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<ui version="4.0" >
|
<ui version="4.0" >
|
||||||
<author>Kovid Goyal</author>
|
<author>Kovid Goyal</author>
|
||||||
<class>MainWindow</class>
|
<class>MainWindow</class>
|
||||||
@ -12,7 +11,7 @@
|
|||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy" >
|
<property name="sizePolicy" >
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@ -34,7 +33,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="LocationView" name="location_view" >
|
<widget class="LocationView" name="location_view" >
|
||||||
<property name="sizePolicy" >
|
<property name="sizePolicy" >
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@ -51,12 +50,21 @@
|
|||||||
<property name="horizontalScrollBarPolicy" >
|
<property name="horizontalScrollBarPolicy" >
|
||||||
<enum>Qt::ScrollBarAsNeeded</enum>
|
<enum>Qt::ScrollBarAsNeeded</enum>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="editTriggers" >
|
||||||
|
<set>QAbstractItemView::NoEditTriggers</set>
|
||||||
|
</property>
|
||||||
<property name="tabKeyNavigation" >
|
<property name="tabKeyNavigation" >
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="showDropIndicator" stdset="0" >
|
<property name="showDropIndicator" stdset="0" >
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="selectionMode" >
|
||||||
|
<enum>QAbstractItemView::NoSelection</enum>
|
||||||
|
</property>
|
||||||
|
<property name="selectionBehavior" >
|
||||||
|
<enum>QAbstractItemView::SelectRows</enum>
|
||||||
|
</property>
|
||||||
<property name="iconSize" >
|
<property name="iconSize" >
|
||||||
<size>
|
<size>
|
||||||
<width>40</width>
|
<width>40</width>
|
||||||
@ -111,7 +119,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="vanity" >
|
<widget class="QLabel" name="vanity" >
|
||||||
<property name="sizePolicy" >
|
<property name="sizePolicy" >
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@ -196,7 +204,7 @@
|
|||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy" >
|
<property name="sizePolicy" >
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
<sizepolicy vsizetype="Fixed" hsizetype="Expanding" >
|
||||||
<horstretch>1</horstretch>
|
<horstretch>1</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@ -205,10 +213,10 @@
|
|||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip" >
|
<property name="toolTip" >
|
||||||
<string>Search the list of books by title or author<br><br>Words separated by spaces are ANDed</string>
|
<string>Search the list of books by title or author<br><br>Words separated by spaces are ANDed</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="whatsThis" >
|
<property name="whatsThis" >
|
||||||
<string>Search the list of books by title, author, publisher, tags and comments<br><br>Words separated by spaces are ANDed</string>
|
<string>Search the list of books by title, author, publisher, tags and comments<br><br>Words separated by spaces are ANDed</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="autoFillBackground" >
|
<property name="autoFillBackground" >
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
@ -274,7 +282,7 @@
|
|||||||
<item row="2" column="0" >
|
<item row="2" column="0" >
|
||||||
<widget class="QStackedWidget" name="stack" >
|
<widget class="QStackedWidget" name="stack" >
|
||||||
<property name="sizePolicy" >
|
<property name="sizePolicy" >
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
|
||||||
<horstretch>100</horstretch>
|
<horstretch>100</horstretch>
|
||||||
<verstretch>100</verstretch>
|
<verstretch>100</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@ -336,7 +344,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="BooksView" name="library_view" >
|
<widget class="BooksView" name="library_view" >
|
||||||
<property name="sizePolicy" >
|
<property name="sizePolicy" >
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
|
||||||
<horstretch>100</horstretch>
|
<horstretch>100</horstretch>
|
||||||
<verstretch>10</verstretch>
|
<verstretch>10</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@ -376,7 +384,7 @@
|
|||||||
<item row="0" column="0" >
|
<item row="0" column="0" >
|
||||||
<widget class="DeviceBooksView" name="memory_view" >
|
<widget class="DeviceBooksView" name="memory_view" >
|
||||||
<property name="sizePolicy" >
|
<property name="sizePolicy" >
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
|
||||||
<horstretch>100</horstretch>
|
<horstretch>100</horstretch>
|
||||||
<verstretch>10</verstretch>
|
<verstretch>10</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@ -414,7 +422,7 @@
|
|||||||
<item row="0" column="0" >
|
<item row="0" column="0" >
|
||||||
<widget class="DeviceBooksView" name="card_view" >
|
<widget class="DeviceBooksView" name="card_view" >
|
||||||
<property name="sizePolicy" >
|
<property name="sizePolicy" >
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
<sizepolicy vsizetype="Expanding" hsizetype="Preferred" >
|
||||||
<horstretch>10</horstretch>
|
<horstretch>10</horstretch>
|
||||||
<verstretch>10</verstretch>
|
<verstretch>10</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
@ -658,15 +666,6 @@
|
|||||||
<string>Books with the same tags</string>
|
<string>Books with the same tags</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="action_send_specific_format_to_device">
|
|
||||||
<property name="icon">
|
|
||||||
<iconset resource="images.qrc">
|
|
||||||
<normaloff>:/images/book.svg</normaloff>:/images/book.svg</iconset>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Send specific format to device</string>
|
|
||||||
</property>
|
|
||||||
</action>
|
|
||||||
<action name="action_preferences" >
|
<action name="action_preferences" >
|
||||||
<property name="icon" >
|
<property name="icon" >
|
||||||
<iconset resource="images.qrc" >
|
<iconset resource="images.qrc" >
|
||||||
|
@ -9,7 +9,7 @@ from PyQt4.QtGui import QListView, QIcon, QFont, QLabel, QListWidget, \
|
|||||||
QSyntaxHighlighter, QCursor, QColor, QWidget, QDialog, \
|
QSyntaxHighlighter, QCursor, QColor, QWidget, QDialog, \
|
||||||
QPixmap, QMovie
|
QPixmap, QMovie
|
||||||
from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, SIGNAL, \
|
from PyQt4.QtCore import QAbstractListModel, QVariant, Qt, SIGNAL, \
|
||||||
QObject, QRegExp, QSettings, QSize
|
QRegExp, QSettings, QSize, QModelIndex
|
||||||
|
|
||||||
from calibre.gui2.jobs2 import DetailView
|
from calibre.gui2.jobs2 import DetailView
|
||||||
from calibre.gui2 import human_readable, NONE, TableView, \
|
from calibre.gui2 import human_readable, NONE, TableView, \
|
||||||
@ -218,7 +218,8 @@ class LocationModel(QAbstractListModel):
|
|||||||
|
|
||||||
def location_changed(self, row):
|
def location_changed(self, row):
|
||||||
self.highlight_row = row
|
self.highlight_row = row
|
||||||
self.reset()
|
self.emit(SIGNAL('dataChanged(QModelIndex,QModelIndex)'),
|
||||||
|
self.index(0), self.index(self.rowCount(QModelIndex())-1))
|
||||||
|
|
||||||
class LocationView(QListView):
|
class LocationView(QListView):
|
||||||
|
|
||||||
@ -226,17 +227,19 @@ class LocationView(QListView):
|
|||||||
QListView.__init__(self, parent)
|
QListView.__init__(self, parent)
|
||||||
self.setModel(LocationModel(self))
|
self.setModel(LocationModel(self))
|
||||||
self.reset()
|
self.reset()
|
||||||
QObject.connect(self.selectionModel(), SIGNAL('currentChanged(QModelIndex, QModelIndex)'), self.current_changed)
|
|
||||||
self.setCursor(Qt.PointingHandCursor)
|
self.setCursor(Qt.PointingHandCursor)
|
||||||
|
self.currentChanged = self.current_changed
|
||||||
|
|
||||||
def count_changed(self, new_count):
|
def count_changed(self, new_count):
|
||||||
self.model().count = new_count
|
self.model().count = new_count
|
||||||
self.model().reset()
|
self.model().reset()
|
||||||
|
|
||||||
def current_changed(self, current, previous):
|
def current_changed(self, current, previous):
|
||||||
|
if current.isValid():
|
||||||
i = current.row()
|
i = current.row()
|
||||||
location = 'library' if i == 0 else 'main' if i == 1 else 'card'
|
location = 'library' if i == 0 else 'main' if i == 1 else 'card'
|
||||||
self.emit(SIGNAL('location_selected(PyQt_PyObject)'), location)
|
self.emit(SIGNAL('location_selected(PyQt_PyObject)'), location)
|
||||||
|
self.model().location_changed(i)
|
||||||
|
|
||||||
def location_changed(self, row):
|
def location_changed(self, row):
|
||||||
if 0 <= row and row <= 2:
|
if 0 <= row and row <= 2:
|
||||||
|
@ -25,7 +25,8 @@ if iswindows:
|
|||||||
else:
|
else:
|
||||||
Structure = _Structure
|
Structure = _Structure
|
||||||
if hasattr(sys, 'frozen') and iswindows:
|
if hasattr(sys, 'frozen') and iswindows:
|
||||||
_libunrar = cdll.LoadLibrary(os.path.join(os.path.dirname(sys.executable), 'unrar.dll'))
|
_libunrar = cdll.LoadLibrary(os.path.join(os.path.dirname(sys.executable),
|
||||||
|
'unrar.dll'))
|
||||||
_libunrar = load_library(_librar_name, cdll)
|
_libunrar = load_library(_librar_name, cdll)
|
||||||
|
|
||||||
RAR_OM_LIST = 0
|
RAR_OM_LIST = 0
|
||||||
|
@ -69,6 +69,7 @@ entry_points = {
|
|||||||
'calibre-customize = calibre.customize.ui:main',
|
'calibre-customize = calibre.customize.ui:main',
|
||||||
'pdftrim = calibre.ebooks.pdf.pdftrim:main' ,
|
'pdftrim = calibre.ebooks.pdf.pdftrim:main' ,
|
||||||
'fetch-ebook-metadata = calibre.ebooks.metadata.fetch:main',
|
'fetch-ebook-metadata = calibre.ebooks.metadata.fetch:main',
|
||||||
|
'calibre-smtp = calibre.utils.smtp:main',
|
||||||
],
|
],
|
||||||
'gui_scripts' : [
|
'gui_scripts' : [
|
||||||
__appname__+' = calibre.gui2.main:main',
|
__appname__+' = calibre.gui2.main:main',
|
||||||
@ -198,6 +199,7 @@ def setup_completion(fatal_errors):
|
|||||||
from calibre.ebooks.metadata.fetch import option_parser as fem_op
|
from calibre.ebooks.metadata.fetch import option_parser as fem_op
|
||||||
from calibre.ebooks.mobi.writer import option_parser as oeb2mobi
|
from calibre.ebooks.mobi.writer import option_parser as oeb2mobi
|
||||||
from calibre.gui2.main import option_parser as guiop
|
from calibre.gui2.main import option_parser as guiop
|
||||||
|
from calibre.utils.email import option_parser as smtp_op
|
||||||
any_formats = ['epub', 'htm', 'html', 'xhtml', 'xhtm', 'rar', 'zip',
|
any_formats = ['epub', 'htm', 'html', 'xhtml', 'xhtm', 'rar', 'zip',
|
||||||
'txt', 'lit', 'rtf', 'pdf', 'prc', 'mobi', 'fb2', 'odt']
|
'txt', 'lit', 'rtf', 'pdf', 'prc', 'mobi', 'fb2', 'odt']
|
||||||
f = open_file('/etc/bash_completion.d/libprs500')
|
f = open_file('/etc/bash_completion.d/libprs500')
|
||||||
@ -246,6 +248,7 @@ def setup_completion(fatal_errors):
|
|||||||
f.write(opts_and_words('feeds2epub', feeds2epub, feed_titles))
|
f.write(opts_and_words('feeds2epub', feeds2epub, feed_titles))
|
||||||
f.write(opts_and_words('feeds2mobi', feeds2mobi, feed_titles))
|
f.write(opts_and_words('feeds2mobi', feeds2mobi, feed_titles))
|
||||||
f.write(opts_and_words('fetch-ebook-metadata', fem_op, []))
|
f.write(opts_and_words('fetch-ebook-metadata', fem_op, []))
|
||||||
|
f.write(opts_and_words('calibre-smtp', smtp_op, []))
|
||||||
f.write(opts_and_exts('html2epub', html2epub, ['html', 'htm', 'xhtm', 'xhtml', 'opf']))
|
f.write(opts_and_exts('html2epub', html2epub, ['html', 'htm', 'xhtm', 'xhtml', 'opf']))
|
||||||
f.write(opts_and_exts('html2oeb', html2oeb, ['html', 'htm', 'xhtm', 'xhtml']))
|
f.write(opts_and_exts('html2oeb', html2oeb, ['html', 'htm', 'xhtm', 'xhtml']))
|
||||||
f.write(opts_and_exts('odt2oeb', odt2oeb, ['odt']))
|
f.write(opts_and_exts('odt2oeb', odt2oeb, ['odt']))
|
||||||
|
@ -18,6 +18,7 @@ DEPENDENCIES = [
|
|||||||
('lxml', '2.1.5', 'lxml', 'python-lxml', 'python-lxml'),
|
('lxml', '2.1.5', 'lxml', 'python-lxml', 'python-lxml'),
|
||||||
('python-dateutil', '1.4.1', 'python-dateutil', 'python-dateutil', 'python-dateutil'),
|
('python-dateutil', '1.4.1', 'python-dateutil', 'python-dateutil', 'python-dateutil'),
|
||||||
('BeautifulSoup', '3.0.5', 'beautifulsoup', 'python-beautifulsoup', 'python-BeautifulSoup'),
|
('BeautifulSoup', '3.0.5', 'beautifulsoup', 'python-beautifulsoup', 'python-BeautifulSoup'),
|
||||||
|
('dnspython', '1.6.0', 'dnspython', 'dnspython', 'dnspython', 'dnspython'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
232
src/calibre/utils/smtp.py
Normal file
232
src/calibre/utils/smtp.py
Normal file
@ -0,0 +1,232 @@
|
|||||||
|
from __future__ import with_statement
|
||||||
|
__license__ = 'GPL 3'
|
||||||
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
|
__docformat__ = 'restructuredtext en'
|
||||||
|
'''
|
||||||
|
This module implements a simple commandline SMTP client that supports:
|
||||||
|
|
||||||
|
* Delivery via an SMTP relay with SSL or TLS
|
||||||
|
* Background delivery with failures being saved in a maildir mailbox
|
||||||
|
'''
|
||||||
|
|
||||||
|
import sys, traceback, os
|
||||||
|
from email import encoders
|
||||||
|
|
||||||
|
def create_mail(from_, to, subject, text=None, attachment_data=None,
|
||||||
|
attachment_type=None, attachment_name=None):
|
||||||
|
assert text or attachment_data
|
||||||
|
|
||||||
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
|
||||||
|
outer = MIMEMultipart()
|
||||||
|
outer['Subject'] = subject
|
||||||
|
outer['To'] = to
|
||||||
|
outer['From'] = from_
|
||||||
|
outer.preamble = 'You will not see this in a MIME-aware mail reader.\n'
|
||||||
|
|
||||||
|
if text is not None:
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
msg = MIMEText(text)
|
||||||
|
outer.attach(msg)
|
||||||
|
|
||||||
|
if attachment_data is not None:
|
||||||
|
from email.mime.base import MIMEBase
|
||||||
|
assert attachment_data and attachment_name
|
||||||
|
maintype, subtype = attachment_type.split('/', 1)
|
||||||
|
msg = MIMEBase(maintype, subtype)
|
||||||
|
msg.set_payload(attachment_data)
|
||||||
|
encoders.encode_base64(msg)
|
||||||
|
msg.add_header('Content-Disposition', 'attachment',
|
||||||
|
filename=attachment_name)
|
||||||
|
outer.attach(msg)
|
||||||
|
|
||||||
|
return outer.as_string()
|
||||||
|
|
||||||
|
def get_mx(host):
|
||||||
|
import dns.resolver
|
||||||
|
answers = list(dns.resolver.query(host, 'MX'))
|
||||||
|
answers.sort(cmp=lambda x, y: cmp(int(x.preference), int(y.preference)))
|
||||||
|
return [str(x.exchange) for x in answers]
|
||||||
|
|
||||||
|
def sendmail_direct(from_, to, msg, timeout, localhost, verbose):
|
||||||
|
import smtplib
|
||||||
|
s = smtplib.SMTP(timeout=timeout, local_hostname=localhost)
|
||||||
|
s.set_debuglevel(verbose)
|
||||||
|
hosts = get_mx(to.split('@')[-1].strip())
|
||||||
|
if not hosts:
|
||||||
|
raise ValueError('No mail server found for address: %s'%to)
|
||||||
|
last_error = last_traceback = None
|
||||||
|
for host in hosts:
|
||||||
|
try:
|
||||||
|
s.connect(host, 25)
|
||||||
|
s.sendmail(from_, [to], msg)
|
||||||
|
return s.quit()
|
||||||
|
except Exception, e:
|
||||||
|
last_error, last_traceback = e, traceback.format_exc()
|
||||||
|
if last_error is not None:
|
||||||
|
print last_traceback
|
||||||
|
raise IOError('Failed to send mail: '+repr(last_error))
|
||||||
|
|
||||||
|
|
||||||
|
def sendmail(msg, from_, to, localhost=None, verbose=0, timeout=30,
|
||||||
|
relay=None, username=None, password=None, encryption='TLS',
|
||||||
|
port=-1):
|
||||||
|
if relay is None:
|
||||||
|
for x in to:
|
||||||
|
return sendmail_direct(from_, x, msg, timeout, localhost, verbose)
|
||||||
|
import smtplib
|
||||||
|
cls = smtplib.SMTP if encryption == 'TLS' else smtplib.SMTP_SSL
|
||||||
|
s = cls(timeout=timeout, local_hostname=localhost)
|
||||||
|
s.set_debuglevel(verbose)
|
||||||
|
if port < 0:
|
||||||
|
port = 25 if encryption == 'TLS' else 465
|
||||||
|
s.connect(relay, port)
|
||||||
|
if encryption == 'TLS':
|
||||||
|
s.starttls()
|
||||||
|
s.ehlo()
|
||||||
|
if username is not None and password is not None:
|
||||||
|
s.login(username, password)
|
||||||
|
s.sendmail(from_, to, msg)
|
||||||
|
return s.quit()
|
||||||
|
|
||||||
|
def option_parser():
|
||||||
|
try:
|
||||||
|
from calibre.utils.config import OptionParser
|
||||||
|
OptionParser
|
||||||
|
except ImportError:
|
||||||
|
from optparse import OptionParser
|
||||||
|
import textwrap
|
||||||
|
parser = OptionParser(textwrap.dedent('''\
|
||||||
|
%prog [options] [from to text]
|
||||||
|
|
||||||
|
Send mail using the SMTP protocol. %prog has two modes of operation. In the
|
||||||
|
compose mode you specify from to and text and these are used to build and
|
||||||
|
send an email message. In the filter mode, %prog reads a complete email
|
||||||
|
message from STDIN and sends it.
|
||||||
|
|
||||||
|
text is the body of the email message.
|
||||||
|
If text is not specified, a complete email message is read from STDIN.
|
||||||
|
from is the email address of the sender and to is the email address
|
||||||
|
of the recipient. When a complete email is read from STDIN, from and to
|
||||||
|
are only used in the SMTP negotiation, the message headers are not modified.
|
||||||
|
'''))
|
||||||
|
c=parser.add_option_group('COMPOSE MAIL',
|
||||||
|
'Options to compose an email. Ignored if text is not specified').add_option
|
||||||
|
c('-a', '--attachment', help='File to attach to the email')
|
||||||
|
c('-s', '--subject', help='Subject of the email')
|
||||||
|
|
||||||
|
parser.add_option('-l', '--localhost',
|
||||||
|
help=('Host name of localhost. Used when connecting '
|
||||||
|
'to SMTP server.'))
|
||||||
|
r=parser.add_option_group('SMTP RELAY',
|
||||||
|
'Options to use an SMTP relay server to send mail. '
|
||||||
|
'%prog will try to send the email directly unless --relay is '
|
||||||
|
'specified.').add_option
|
||||||
|
r('-r', '--relay', help=('An SMTP relay server to use to send mail.'))
|
||||||
|
r('-p', '--port', default=-1,
|
||||||
|
help='Port to connect to on relay server. Default is to use 465 if '
|
||||||
|
'encryption method is SSL and 25 otherwise.')
|
||||||
|
r('-u', '--username', help='Username for relay')
|
||||||
|
r('-p', '--password', help='Password for relay')
|
||||||
|
r('-e', '--encryption-method', default='TLS',
|
||||||
|
choices=['TLS', 'SSL'],
|
||||||
|
help='Encryption method to use when connecting to relay. Choices are '
|
||||||
|
'TLS and SSL. Default is TLS.')
|
||||||
|
parser.add_option('-o', '--outbox', help='Path to maildir folder to store '
|
||||||
|
'failed email messages in.')
|
||||||
|
parser.add_option('-f', '--fork', default=False, action='store_true',
|
||||||
|
help='Fork and deliver message in background. '
|
||||||
|
'If you use this option, you should also use --outbox '
|
||||||
|
'to handle delivery failures.')
|
||||||
|
parser.add_option('-t', '--timeout', help='Timeout for connection')
|
||||||
|
parser.add_option('-v', '--verbose', default=0, action='count',
|
||||||
|
help='Be more verbose')
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def extract_email_address(raw):
|
||||||
|
from email.utils import parseaddr
|
||||||
|
return parseaddr(raw)[-1]
|
||||||
|
|
||||||
|
def compose_mail(from_, to, text, subject=None, attachment=None,
|
||||||
|
attachment_name=None):
|
||||||
|
attachment_type = attachment_data = None
|
||||||
|
if attachment is not None:
|
||||||
|
try:
|
||||||
|
from calibre import guess_type
|
||||||
|
guess_type
|
||||||
|
except ImportError:
|
||||||
|
from mimetypes import guess_type
|
||||||
|
attachment_data = attachment.read() if hasattr(attachment, 'read') \
|
||||||
|
else open(attachment, 'rb').read()
|
||||||
|
attachment_type = guess_type(getattr(attachment, 'name', attachment))[0]
|
||||||
|
if attachment_name is None:
|
||||||
|
attachment_name = os.path.basename(getattr(attachment,
|
||||||
|
'name', attachment))
|
||||||
|
subject = subject if subject else 'no subject'
|
||||||
|
return create_mail(from_, to, subject, text=text,
|
||||||
|
attachment_data=attachment_data, attachment_type=attachment_type,
|
||||||
|
attachment_name=attachment_name)
|
||||||
|
|
||||||
|
def main(args=sys.argv):
|
||||||
|
parser = option_parser()
|
||||||
|
opts, args = parser.parse_args(args)
|
||||||
|
|
||||||
|
|
||||||
|
if len(args) > 1:
|
||||||
|
msg = compose_mail(args[1], args[2], args[3], subject=opts.subject,
|
||||||
|
attachment=opts.attachment)
|
||||||
|
from_, to = args[1:3]
|
||||||
|
efrom, eto = map(extract_email_address, (from_, to))
|
||||||
|
eto = [eto]
|
||||||
|
else:
|
||||||
|
msg = sys.stdin.read()
|
||||||
|
from email.parser import Parser
|
||||||
|
from email.utils import getaddresses
|
||||||
|
eml = Parser.parsestr(msg, headersonly=True)
|
||||||
|
tos = eml.get_all('to', [])
|
||||||
|
ccs = eml.get_all('cc', [])
|
||||||
|
eto = getaddresses(tos + ccs)
|
||||||
|
if not eto:
|
||||||
|
raise ValueError('Email from STDIN does not specify any recipients')
|
||||||
|
efrom = getaddresses(eml.get_all('from', []))
|
||||||
|
if not efrom:
|
||||||
|
raise ValueError('Email from STDIN does not specify a sender')
|
||||||
|
efrom = efrom[0]
|
||||||
|
|
||||||
|
|
||||||
|
outbox = None
|
||||||
|
if opts.outbox is not None:
|
||||||
|
outbox = os.path.abspath(os.path.expanduser(opts.outbox))
|
||||||
|
from mailbox import Maildir
|
||||||
|
outbox = Maildir(opts.outbox, factory=None)
|
||||||
|
if opts.fork:
|
||||||
|
if os.fork() != 0:
|
||||||
|
return 0
|
||||||
|
try:
|
||||||
|
sendmail(msg, efrom, eto, localhost=opts.localhost, verbose=opts.verbose,
|
||||||
|
timeout=opts.timeout, relay=opts.relay, username=opts.username,
|
||||||
|
password=opts.password, port=opts.port,
|
||||||
|
encryption=opts.encryption_method)
|
||||||
|
except:
|
||||||
|
if outbox is not None:
|
||||||
|
outbox.add(msg)
|
||||||
|
print 'Delivery failed. Message saved to', opts.outbox
|
||||||
|
raise
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def config(defaults=None):
|
||||||
|
from calibre.utils.config import Config, StringConfig
|
||||||
|
desc = _('Control email delivery')
|
||||||
|
c = Config('smtp',desc) if defaults is None else StringConfig(defaults,desc)
|
||||||
|
c.add_opt('from_')
|
||||||
|
c.add_opt('accounts', default={})
|
||||||
|
c.add_opt('relay_host')
|
||||||
|
c.add_opt('relay_port', default=25)
|
||||||
|
c.add_opt('relay_username')
|
||||||
|
c.add_opt('relay_password')
|
||||||
|
c.add_opt('encryption', default='TLS', choices=['TLS', 'SSL'])
|
||||||
|
return c
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(main())
|
@ -43,6 +43,5 @@ class SpeigelOnline(BasicNewsRecipe):
|
|||||||
for y in reversed(soup.contents):
|
for y in reversed(soup.contents):
|
||||||
x.contents[0].insert(0, y)
|
x.contents[0].insert(0, y)
|
||||||
soup = x
|
soup = x
|
||||||
print 1111111
|
|
||||||
|
|
||||||
return soup
|
return soup
|
||||||
|
Loading…
x
Reference in New Issue
Block a user