예제 #1
0
파일: addr.py 프로젝트: ivicac/sync-engine
def parse_mimepart_address_header(mimepart, header_name):
    # type: (MimePart, str) -> List[List[str]]
    # Header parsing is complicated by the fact that:
    # (1) You can have multiple occurrences of the same header;
    # (2) Phrases or comments can be RFC2047-style encoded words;
    # (3) Everything is terrible.
    # Here, for each occurrence of the header in question, we first parse
    # it into a list of (phrase, addrspec) tuples and then use flanker to
    # decode any encoded words.
    # You want to do it in that order, because otherwise if you get a header
    # like
    # From: =?utf-8?Q?FooCorp=2C=20Inc.=? <*****@*****.**>
    # you can end up parsing 'FooCorp, Inc. <*****@*****.**> (note lack of
    # quoting) into two separate addresses.
    # Consult RFC822 Section 6.1 and RFC2047 section 5 for details.
    addresses = set()  # type: Set[Tuple[str, str]]
    for section in mimepart.headers._v.getall(normalize(header_name)):
        for phrase, addrspec in email.utils.getaddresses([section]):
            if not addrspec and not phrase:
                continue
            addresses.add((decode(phrase), decode(addrspec)))

    # Return a list of lists because it makes it easier to compare an address
    # field to one which has been fetched from the db.
    return sorted(list(elem) for elem in addresses)
예제 #2
0
파일: headers.py 프로젝트: rcharp/airform
 def __setitem__(self, key, value):
     key = normalize(key)
     if key in self._v:
         self._v[key] = remove_newlines(value)
         self.changed = True
     else:
         self.prepend(key, remove_newlines(value))
예제 #3
0
파일: headers.py 프로젝트: rcharp/airform
 def get(self, key, default=None):
     """
     Returns header value (case-insensitive).
     """
     v = self._v.get(normalize(key), default)
     if v is not None:
         return encodedword.decode(v)
     return None
예제 #4
0
def parse_mimepart_address_header(mimepart, header_name):
    # Header parsing is complicated by the fact that:
    # (1) You can have multiple occurrences of the same header;
    # (2) Phrases or comments can be RFC2047-style encoded words;
    # (3) Everything is terrible.
    # Here, for each occurrence of the header in question, we first parse
    # it into a list of (phrase, addrspec) tuples and then use flanker to
    # decode any encoded words.
    # You want to do it in that order, because otherwise if you get a header
    # like
    # From: =?utf-8?Q?FooCorp=2C=20Inc.=? <*****@*****.**>
    # you can end up parsing 'FooCorp, Inc. <*****@*****.**> (note lack of
    # quoting) into two separate addresses.
    # Consult RFC822 Section 6.1 and RFC2047 section 5 for details.
    addresses = set()
    for section in mimepart.headers._v.getall(normalize(header_name)):
        for phrase, addrspec in rfc822.AddressList(section).addresslist:
            addresses.add((decode(phrase), decode(addrspec)))

    # Return a list of lists because it makes it easier to compare an address
    # field to one which has been fetched from the db.
    return sorted(list(elem) for elem in addresses)
예제 #5
0
파일: headers.py 프로젝트: rcharp/airform
 def getraw(self, key, default=None):
     """
     Returns raw header value (case-insensitive, non-decoded.
     """
     return self._v.get(normalize(key), default)
예제 #6
0
파일: headers.py 프로젝트: rcharp/airform
 def getall(self, key):
     """
     Returns all header values by the given header name (case-insensitive).
     """
     v = self._v.getall(normalize(key))
     return [encodedword.decode(x) for x in v]
예제 #7
0
파일: headers.py 프로젝트: Appono/flanker
 def getall(self, key):
     """
     Returns all header values by the given header name
     (case-insensitive)
     """
     return self._v.getall(normalize(key))
예제 #8
0
 def __getitem__(self, key):
     return self.v.get(normalize(key), None)
예제 #9
0
파일: headers.py 프로젝트: Appono/flanker
    def add(self, key, value):
        """Adds header without changing the
        existing headers with same name"""

        self._v.add(normalize(key), remove_newlines(value))
        self.changed = True
예제 #10
0
파일: headers.py 프로젝트: Appono/flanker
 def get(self, key, default=None):
     """
     Returns header value (case-insensitive).
     """
     return self._v.get(normalize(key), default)
예제 #11
0
파일: headers.py 프로젝트: rcharp/airform
 def __delitem__(self, key):
     del self._v[normalize(key)]
     self.changed = True
예제 #12
0
 def __init__(self, items=()):
     self.v = MultiDict([(normalize(key), val) for (key, val) in items])
     self.changed = False
예제 #13
0
파일: headers.py 프로젝트: rcharp/airform
 def __init__(self, items=()):
     self._v = MultiDict([(normalize(key), remove_newlines(val))
                          for (key, val) in items])
     self.changed = False
     self.num_prepends = 0
예제 #14
0
파일: headers.py 프로젝트: rcharp/airform
 def __contains__(self, key):
     return normalize(key) in self._v
예제 #15
0
 def __setitem__(self, key, value):
     self.v[normalize(key)] = _remove_newlines(value)
     self.changed = True
예제 #16
0
파일: headers.py 프로젝트: wichert/flanker
 def __init__(self, items=()):
     self.v = MultiDict(
         [(normalize(key), val) for (key, val) in items])
     self.changed = False
예제 #17
0
 def getall(self, key):
     """
     Returns all header values by the given header name
     (case-insensitive)
     """
     return self.v.getall(normalize(key))
예제 #18
0
 def get(self, key, default=None):
     """
     Returns header value (case-insensitive).
     """
     return self.v.get(normalize(key), default)
예제 #19
0
    def add(self, key, value):
        """Adds header without changing the
        existing headers with same name"""

        self.v.add(normalize(key), _remove_newlines(value))
        self.changed = True
예제 #20
0
파일: headers.py 프로젝트: rcharp/airform
 def __getitem__(self, key):
     v = self._v.get(normalize(key), None)
     if v is not None:
         return encodedword.decode(v)
     return None
예제 #21
0
파일: headers.py 프로젝트: Appono/flanker
 def __getitem__(self, key):
     return self._v.get(normalize(key), None)
예제 #22
0
파일: headers.py 프로젝트: Appono/flanker
 def __setitem__(self, key, value):
     self._v[normalize(key)] = remove_newlines(value)
     self.changed = True
예제 #23
0
파일: headers.py 프로젝트: Appono/flanker
 def prepend(self, key, value):
     self._v._items.insert(0, (normalize(key), remove_newlines(value)))
     self.changed = True
예제 #24
0
파일: headers.py 프로젝트: rcharp/airform
 def prepend(self, key, value):
     self._v._items.insert(0, (normalize(key), remove_newlines(value)))
     self.num_prepends += 1
예제 #25
0
 def prepend(self, key, value):
     self._v._items.insert(0, (normalize(key), remove_newlines(value)))
     self.changed = True