def _find_attachments(self): """Retrieve attachments from the parsed body structure. We try to find and decode a file name for each attachment. If we failed, a generic name will be used (ie. part_1, part_2, ...). """ for att in self.bs.attachments: attname = "part_%s" % att["pnum"] if "params" in att and att["params"] != "NIL": attname = u2u_decode.u2u_decode(att["params"][1]) \ .strip("\r\t\n") elif "disposition" in att and len(att["disposition"]) > 1: for pos, value in enumerate(att["disposition"][1]): if not value.startswith("filename"): continue header = "%s; %s=%s" \ % (att['disposition'][0], value, att["disposition"][1][pos + 1].strip("\r\t\n")) attname = parse_headers(header).filename_unsafe if attname is None: attname = u2u_decode.u2u_decode( att["disposition"][1][pos + 1] ).strip("\r\t\n") break self.attachments[att["pnum"]] = attname
def _find_attachments(self): """Retrieve attachments from the parsed body structure. We try to find and decode a file name for each attachment. If we failed, a generic name will be used (ie. part_1, part_2, ...). """ for att in self.bs.attachments: attname = "part_%s" % att["pnum"] if "params" in att and att["params"] != "NIL": attname = u2u_decode.u2u_decode(att["params"][1]) \ .strip("\r\t\n") elif "disposition" in att and len(att["disposition"]) > 1: for pos, value in enumerate(att["disposition"][1]): if not value.startswith("filename"): continue header = "%s; %s=%s" \ % (att['disposition'][0], value, att["disposition"][1][pos + 1].strip("\r\t\n")) attname = parse_headers(header).filename_unsafe if attname is None: attname = u2u_decode.u2u_decode( att["disposition"][1][pos + 1]).strip("\r\t\n") break self.attachments[att["pnum"]] = attname
def parse_subject(value, **kwargs): """Parse a Subject: header.""" from modoboa.lib import u2u_decode try: subject = u2u_decode.u2u_decode(value) except UnicodeDecodeError: subject = value return to_unicode(subject)
def parse_subject(value, **kwargs): """Parse a Subject: header. """ from modoboa.lib import u2u_decode try: subject = u2u_decode.u2u_decode(value) except UnicodeDecodeError: subject = value return to_unicode(subject)
def _find_attachments(self): """Retrieve attachments from the parsed body structure. We try to find and decode a file name for each attachment. If we failed, a generic name will be used (ie. part_1, part_2, ...). """ for att in self.bs.attachments: attname = "part_{}".format(att["pnum"]) if "params" in att and att["params"] != "NIL": for pos, value in enumerate(att["params"]): if not value.startswith("name"): continue attname = (u2u_decode.u2u_decode( att["params"][pos + 1]).strip("\r\t\n")) break elif "disposition" in att and len(att["disposition"]) > 1: for pos, value in enumerate(att["disposition"][1]): if not value.startswith("filename"): continue attname = u2u_decode.u2u_decode( att["disposition"][1][pos + 1]).strip("\r\t\n") break self.attachments[att["pnum"]] = smart_text(attname)
def _find_attachments(self): for att in self.bs.attachments: attname = "part_%s" % att["pnum"] params = None key = None if "params" in att and att["params"] != "NIL": params = att["params"] key = "name" if key is None and "disposition" in att and len(att["disposition"]) > 1: params = att["disposition"][1] key = "filename" if key and params: for pos, value in enumerate(params): if not value.startswith(key): continue header = "%s; %s=%s" % (att['disposition'][0], value, u2u_decode.u2u_decode(params[pos + 1]).strip("\r\t\n")) attname = parse_headers(header).filename_unsafe if attname is None: attname = u2u_decode.u2u_decode(params[pos + 1]).strip("\r\t\n") break self.attachments[att["pnum"]] = attname
def _find_attachments(self): for att in self.bs.attachments: attname = "part_%s" % att["pnum"] params = None key = None if att.has_key("params") and att["params"] != "NIL": params = att["params"] key = "name" if key is None and att.has_key("disposition") and len(att["disposition"]) > 1: params = att["disposition"][1] key = "filename" if key and params: for pos, value in enumerate(params): if value == key: attname = u2u_decode.u2u_decode(params[pos + 1]).strip("\r\t\n") break self.attachments[att["pnum"]] = attname
def _find_attachments(self): for att in self.bs.attachments: attname = "part_%s" % att["pnum"] params = None key = None if att.has_key("params") and att["params"] != "NIL": params = att["params"] key = "name" if key is None and \ att.has_key("disposition") and len(att["disposition"]) > 1: params = att["disposition"][1] key = "filename" if key and params: for pos, value in enumerate(params): if value == key: attname = u2u_decode.u2u_decode( params[pos + 1]).strip("\r\t\n") break self.attachments[att["pnum"]] = attname
def __init__(self, address): self.fulladdress = u2u_decode.u2u_decode(address).strip("\r\t\n") (self.name, self.address) = parseaddr(self.fulladdress) if self.name == "": self.fulladdress = self.address
def parse_subject(value, **kwargs): try: subject = u2u_decode.u2u_decode(value) except UnicodeDecodeError: subject = value return IMAPheader.to_unicode(subject)