def _time (self) : date = self._get_header_ ("date", "Date") if date : parsed = Lib.parsedate_tz (date) if parsed is not None : try : return Lib.mktime_tz (parsed) except (OverflowError, ValueError) : pass
def _time(self): date = self._get_header_("date", "Date") if date: parsed = Lib.parsedate_tz(date) if parsed is not None: try: return Lib.mktime_tz(parsed) except (OverflowError, ValueError): pass
def _finish_forward (self, msg, more_msgs, buffer, bfn = None) : if buffer : email = msg.email envelope = self._as_multipart (self._as_message (buffer)) envelope.attach (Lib.MIMEMessage (email)) for m in more_msgs : envelope.attach (Lib.MIMEMessage (m.email)) self._finish__send (envelope) if bfn is not None : TFL.sos.unlink (bfn)
def _finish_resend (self, msg, buffer, bfn = None) : if buffer : email = msg.email envelope = self._as_message (buffer) for k in envelope.keys () : if k.lower () not in ("bcc", "dcc") : n = "Resent-%s" % k for h in envelope.get_all (k, []) : if h : email [n] = h email ["Resent-date"] = Lib.formatdate () email ["Resent-message-id"] = Lib.make_msgid () self._finish__send (email, envelope = envelope) if bfn is not None : TFL.sos.unlink (bfn)
def _new_email (self, fp, headersonly = False) : result = Lib.message_from_file (fp) result._pma_parsed_body = True self.n += 1 result._pma_path = str (self.n) result._pma_dir = None return result
def __init__ (self, path, prefix = None, root = None) : if not sos.path.isdir (path) : sos.mkdir (path) self.parser = Lib.Parser () self.__super.__init__ (path, prefix = prefix, root = root) for s in self._subdirs (path) : self._new_subbox (s)
def message_from_file(filename, parser=None): if parser is None: parser = Lib.Parser() with open(filename, "rb") as fp: email = parser.parse(fp) email._pma_parsed_body = True return PMA.Message(email, sos.path.split(filename)[-1])
def _get_sender_ (self) : msg = self.msg result = (None, None) sender = msg._get_header_ ("sender", "Sender") if sender is None : sender = msg.email.get_unixfrom () if sender is not None : result = Lib.getaddresses ((sender, )) [0] or result return result
def _get_sender_(self): msg = self.msg result = (None, None) sender = msg._get_header_("sender", "Sender") if sender is None: sender = msg.email.get_unixfrom() if sender is not None: result = Lib.getaddresses((sender, ))[0] or result return result
def __getitem__ (self, key) : map = self.aliases rn, ea = Lib.parseaddr (key) l, s, d = split_hst (ea, "@") if s : try : return map [l] except KeyError : pass return map [ea]
def decoded_header(header): result = [] if header: for p, c in Lib.decode_header(header): enc = c or PMA.default_encoding if enc == "unknown": enc = PMA.default_encoding result.append(pyk.decoded(p, enc)) result = " ".join(result) return result
def decoded_header (header) : result = [] if header : for p, c in Lib.decode_header (header) : enc = c or PMA.default_encoding if enc == "unknown" : enc = PMA.default_encoding result.append (pyk.decoded (p, enc)) result = " ".join (result) return result
def _as_multipart (self, email, ** kw) : result = email if not email.is_multipart () : result = Lib.MIMEMultipart (** kw) ignore = set (result.keys ()) for k, v in email.items () : if k not in ignore : result [k] = v result.attach (self._as_text_part (email)) return result
def _reparsed (self) : result = self.email if self.path and not result._pma_parsed_body : if self.mailbox : result = self.mailbox.reparsed (self) else : with open (self.path, "r") as fp : result = Lib.message_from_file (fp) result._pma_dir = getattr (self.email, "_pma_dir", None) result._pma_path = getattr (self.email, "_pma_path", None) result._pma_parsed_body = True self.email = result self._setup_body (result) return result
def _reparsed(self): result = self.email if self.path and not result._pma_parsed_body: if self.mailbox: result = self.mailbox.reparsed(self) else: with open(self.path, "rb") as fp: result = Lib.message_from_file(fp) result._pma_dir = getattr(self.email, "_pma_dir", None) result._pma_path = getattr(self.email, "_pma_path", None) result._pma_parsed_body = True self.email = result self._setup_body(result) return result
def __init__ ( self, maildir, host, user , passwd = None , port = 110 , poll_interval = 10 ### in seconds , ** kw ) : self.maildir = maildir self.host = host self.port = port self.user = user self.passwd = passwd self.poll_interval = poll_interval self.finish = False self.parser = Lib.Parser () self.__super.__init__ (** kw)
def messages_from_args(args, base_dirs): parser = Lib.Parser() for arg in args: matches = tuple \ ( TFL.CAO.Rel_Path.resolved_paths (base_dirs, arg, single_match = False, skip_missing = True) ) if not matches and sos.path.exists(arg): matches = [arg] if len(matches) == 1: yield PMA.message_from_file(matches[0], parser) elif matches: print \ ( "Multiple matches for %r: choose one of\n %s" % (arg, "\n ".join (matches)) ) else: tail = ("in\n %s" % "\n ".join (base_dirs)) \ if base_dirs else "" print("No match found for %r%s" % (arg, tail))
def addresses (self) : return Lib.getaddresses (self.values)
def _new (self, mt, st, b) : result = self.MIME (mt, st) result.set_payload (b) Lib.encode_base64 (result) return result
def _new(self, mt, st, b): result = self.MIME(mt, st) result.set_payload(b) Lib.encode_base64(result) return result