示例#1
0
    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
示例#2
0
    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
示例#3
0
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)
示例#4
0
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)
示例#5
0
    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)
示例#6
0
    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
示例#7
0
文件: lib.py 项目: juju2013/modoboa
    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
示例#8
0
    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
示例#9
0
 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
示例#10
0
 def parse_subject(value, **kwargs):
     try:
         subject = u2u_decode.u2u_decode(value)
     except UnicodeDecodeError:
         subject = value
     return IMAPheader.to_unicode(subject)
示例#11
0
 def parse_subject(value, **kwargs):
     try:
         subject = u2u_decode.u2u_decode(value)
     except UnicodeDecodeError:
         subject = value
     return IMAPheader.to_unicode(subject)
示例#12
0
 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