def _addresses_from_header (self, addrs) : ### Unfortunately, the `email` package is a f*****g mess of ### incompatibilities between various Python versions and ### **badly documented** on top ### ### * Python 2 returns strings for address headers, e.g., `To`, `cc` ### * Python 3 returns objects for address headers, but which type of ### object isn't documented, except for ### `the returned value is an instance of a subclass of ### email.headerregistry.BaseHeader.` ### - I'd have guessed, the returned object type to be ### `email.headerregistry.AddressHeader` or ### `.SingleAddressHeader` ### but python3.6 then died with:: ### 'Header' object has no attribute 'addresses' try : splitter = addrs.split except AttributeError : try : results = addrs.addresses except AttributeError : results = [pyk.as_str (addrs)] else : results = list (pyk.as_str (r) for r in addrs.addresses) else : results = list (r.strip () for r in splitter (",")) return results
def send (self, from_addr, to_addrs, msg, mail_opts = None, rcpt_opts = None) : charset = self.charset msg_s = pyk.decoded (msg, charset) self._log \ ( pyk.as_str ("[%s] Email via %s from %s to %s\n %s", charset) , datetime.datetime.now ().replace (microsecond = 0) , pyk.as_str (self.mail_host, charset) , pyk.as_str (from_addr, charset) , list (pyk.as_str (t, charset) for t in to_addrs) , pyk.as_str ("\n ".join (msg_s.split ("\n")), charset) )
def conv (s) : return pyk.as_str (s)
def __call__ (self, filter) : return self._pq (pyk.as_str (filter))
def __init__ (self, data) : self._pq = self.PyQuery (pyk.as_str (data))
def _new (self, mt, st, b) : return self.MIME (pyk.as_str (b, "latin-1"), _subtype = st)
def _new (self, mt, st, b) : return self.MIME \ ( pyk.as_str (b, "latin-1") , _subtype = st, _charset = PMA.default_encoding )
def set_header(self, key, value, **kw): key = pyk.as_str(key, "ascii") return self.headers.set(key, value, **kw)
def add_header(self, key, value, **kw): key = pyk.as_str(key, "ascii") return self.headers.add(key, value, **kw)
def _write (self, file, s) : file.write (pyk.as_str (s))
def set_header (self, key, value, ** kw) : key = pyk.as_str (key, "ascii") return self.headers.set (key, value, ** kw)
def add_header (self, key, value, ** kw) : key = pyk.as_str (key, "ascii") return self.headers.add (key, value, ** kw)
def _new(self, mt, st, b): return self.MIME(pyk.as_str(b, "latin-1"), _subtype=st)
def _new(self, mt, st, b): return self.MIME \ ( pyk.as_str (b, "latin-1") , _subtype = st, _charset = PMA.default_encoding )