def SendToKindle(self, name, to, title, booktype, attachment, tz=TIMEZONE, filewithtime=True): if PINYIN_FILENAME: # 将中文文件名转换为拼音 from calibre.ebooks.unihandecode.unidecoder import Unidecoder decoder = Unidecoder() basename = decoder.decode(title) else: basename = title lctime = local_time('%Y-%m-%d_%H-%M',tz) if booktype: if filewithtime: filename = "%s(%s).%s"%(basename,lctime,booktype) else: filename = "%s.%s"%(basename,booktype) else: filename = basename for i in range(SENDMAIL_RETRY_CNT+1): try: mail.send_mail(SRC_EMAIL, to, "KindleEar %s" % lctime, "Deliver from KindleEar", attachments=[(filename, attachment),]) except OverQuotaError as e: default_log.warn('overquota when sendmail to %s:%s' % (to, str(e))) self.deliverlog(name, to, title, len(attachment), tz=tz, status='over quota') default_log.warn('overquota when sendmail to %s:%s, retry!' % (to, str(e))) time.sleep(10) if i>2: break except InvalidSenderError as e: default_log.warn('UNAUTHORIZED_SENDER when sendmail to %s:%s' % (to, str(e))) self.deliverlog(name, to, title, len(attachment), tz=tz, status='wrong SRC_EMAIL') break except InvalidAttachmentTypeError as e: #继续发送一次 if SENDMAIL_ALL_POSTFIX: filename = filename.replace('.', '_') title = title.replace('.', '_') else: default_log.warn('InvalidAttachmentTypeError when sendmail to %s:%s' % (to, str(e))) self.deliverlog(name, to, title, len(attachment), tz=tz, status='invalid postfix') break except DeadlineExceededError as e: if i < SENDMAIL_RETRY_CNT: default_log.warn('timeout when sendmail to %s:%s, retry!' % (to, str(e))) time.sleep(5) else: default_log.warn('timeout when sendmail to %s:%s, abort!' % (to, str(e))) self.deliverlog(name, to, title, len(attachment), tz=tz, status='timeout') break except Exception as e: default_log.warn('sendmail to %s failed:%s.<%s>' % (to, str(e), type(e))) self.deliverlog(name, to, title, len(attachment), tz=tz, status='send failed') break else: self.deliverlog(name, to, title, len(attachment), tz=tz) break
def __init__(self, lang="zh", encoding='utf-8'): self.preferred_encoding = encoding lang = lang.lower() if lang[:2] == 'ja': from calibre.ebooks.unihandecode.jadecoder import Jadecoder self.decoder = Jadecoder() elif lang[:2] == 'kr' or lang == 'korean': from calibre.ebooks.unihandecode.krdecoder import Krdecoder self.decoder = Krdecoder() elif lang[:2] == 'vn' or lang == 'vietnum': from calibre.ebooks.unihandecode.vndecoder import Vndecoder self.decoder = Vndecoder() else: # zh and others from calibre.ebooks.unihandecode.unidecoder import Unidecoder self.decoder = Unidecoder()
def SendToKindle(self, name, to, title, booktype, attachment, tz=TIMEZONE, filewithtime=True): if PINYIN_FILENAME: # 将中文文件名转换为拼音 from calibre.ebooks.unihandecode.unidecoder import Unidecoder decoder = Unidecoder() basename = decoder.decode(title) else: basename = title lctime = local_time('%Y-%m-%d_%H-%M', tz) if filewithtime: filename = "%s(%s).%s" % (basename, lctime, booktype) else: filename = "%s.%s" % (basename, booktype) try: mail.send_mail(SRC_EMAIL, to, "KindleEar %s" % lctime, "Deliver from KindlerEar", attachments=[ (filename, attachment), ]) except OverQuotaError as e: default_log.warn('overquota when sendmail to %s:%s' % (to, str(e))) self.deliverlog(name, to, title, len(attachment), tz=tz, status='over quota') except Exception as e: default_log.warn('sendmail to %s failed:%s' % (to, str(e))) self.deliverlog(name, to, title, len(attachment), tz=tz, status='send failed') else: self.deliverlog(name, to, title, len(attachment), tz=tz)