def make_quoted_printable(message: Message): """ Default is base64, so this can be used to change a Message to quo-pri. """ payload = message.get_payload(decode=True) encdata = _encodestring(payload, quotetabs=True) message.set_payload(encdata) message.replace_header('Content-Transfer-Encoding', 'quoted-printable')
def _qencode(s): enc = _encodestring(s, quotetabs=True) return enc.replace(' ', '=20')
def _qencode(s): enc = _encodestring(s, quotetabs=True) # Must encode spaces, which quopri.encodestring() doesn't do return enc.replace(' ', '=20')
def _qencode(s): enc = _encodestring(s, quotetabs=True) # Must encode spaces, which quopri.encodestring() doesn't do return enc.replace(b' ', b'=20')
# Copyright (C) 2001 Python Software Foundation
def _qencode(s): enc = _encodestring(s, quotetabs=1) # Must encode spaces, which quopri.encodestring() doesn't do return enc.replace(" ", "=20")
def send_file(self, filename, addresses, original=None, mime_type='text/plain', rotate_date=None, charset=None): ''' Mails the file with the given file name as an attachement to the given recipient(s). Raises a LogRotateMailerError on harder errors. @param filename: The file name of the file to send (the existing, rotated and maybe compressed logfile). @type filename: str @param addresses: A list of tuples of a pair in the form of the return value of email.utils.parseaddr() @type addresses: list @param original: The file name of the original (unrotated) logfile for informational purposes. If not given, filename is used instead. @type original: str or None @param mime_type: MIME type (content type) of the original logfile, defaults to 'text/plain' @type mime_type: str @param rotate_date: datetime object of rotation, defaults to now() @type rotate_date: datetime or None @param charset: character set of (uncompreesed) logfile, if the mime_type is 'text/plain', defaults to 'utf-8' @type charset: str or None @return: success of sending @rtype: bool ''' _ = self.t.lgettext if not os.path.exists(filename): msg = _("File '%s' doesn't exists.") % (filename) self.logger.error(msg) return False if not os.path.isfile(filename): msg = _("File '%s' is not a regular file.") % (filename) self.logger.warning(msg) return False basename = os.path.basename(filename) if not original: original = os.path.abspath(filename) if not rotate_date: rotate_date = datetime.now() to_list = [] for address in addresses: to_list.append(address[1]) msg = (_("Sending mail with attached file '%(file)s' to: %(rcpt)s") % { 'file': basename, 'rcpt': ', '.join( map(lambda x: ('"' + email.utils.formataddr(x) + '"'), addresses)) }) self.logger.debug(msg) mail_container = MIMEMultipart() mail_container['Date'] = email.utils.formatdate() mail_container['X-Mailer'] = ("pylogrotate version %s" % (self.mailer_version)) mail_container['From'] = self.from_address mail_container['To'] = ', '.join( map(lambda x: email.utils.formataddr(x), addresses)) mail_container['Subject'] = ("Rotated logfile '%s'" % (filename)) mail_container.preamble = ( 'You will not see this in a MIME-aware mail reader.\n') # Generate Text of the first part of mail body mailtext = "Rotated Logfile:\n\n" mailtext += "\t - " + filename + "\n" mailtext += "\t (" + original + ")\n" mailtext += "\n" mailtext += "Date of rotation: " + rotate_date.isoformat(' ') mailtext += "\n" mailtext = _encodestring(mailtext, quotetabs=False) mail_part = MIMENonMultipart('text', 'plain', charset=sys.getdefaultencoding()) mail_part.set_payload(mailtext) mail_part['Content-Transfer-Encoding'] = 'quoted-printable' mail_container.attach(mail_part) ctype, encoding = mimetypes.guess_type(filename) if self.verbose > 3: msg = (_("Guessed content-type: '%(ctype)s' " + "and encoding '%(encoding)s'.") % { 'ctype': ctype, 'encoding': encoding }) self.logger.debug(msg) if encoding: if encoding == 'gzip': ctype = 'application/x-gzip' elif encoding == 'bzip2': ctype = 'application/x-bzip2' else: ctype = 'application/octet-stream' if not ctype: ctype = mime_type maintype, subtype = ctype.split('/', 1) fp = open(filename, 'rb') mail_part = MIMEBase(maintype, subtype) mail_part.set_payload(fp.read()) fp.close() if maintype == 'text': msgtext = mail_part.get_payload() msgtext = _encodestring(msgtext, quotetabs=False) mail_part.set_payload(msgtext) mail_part['Content-Transfer-Encoding'] = 'quoted-printable' else: encoders.encode_base64(mail_part) mail_part.add_header('Content-Disposition', 'attachment', filename=basename) mail_container.attach(mail_part) composed = mail_container.as_string() if self.verbose > 4: msg = _("Generated E-mail:") + "\n" + composed self.logger.debug(msg) if (not self.use_smtp) and self.sendmail: return self._send_per_sendmail(composed) else: return self._send_per_smtp(composed, to_list) return True
def _qencode(s): return _encodestring(s, quotetabs=1)