Ejemplo n.º 1
0
    def decode(cls, line):
        """Remove backslash escaping from line.valueDecode line, either to remove
        backslash espacing, or to decode base64 encoding. The content line should
        contain a ENCODING=b for base64 encoding, but Apple Addressbook seems to
        export a singleton parameter of 'BASE64', which does not match the 3.0
        vCard spec. If we encouter that, then we transform the parameter to
        ENCODING=b"""
        if line.encoded:
            if 'BASE64' in line.singletonparams:
                line.singletonparams.remove('BASE64')
                line.encoding_param = cls.base64string
            encoding = getattr(line, 'encoding_param', None)
            if encoding:
              if encoding == 'quoted-printable':
                line.value = line.value.encode('utf-8').decode(encoding)

              else:
                try:
                  line.value = line.value.decode('base64')
                except binascii.Error:
                  # Ignore decoding errors caused by invalid base64 values
                  logger.error('Failed to parse vContact value field, setting to an empty string')
                  line.value = ''
            else:
                line.value = stringToTextValues(line.value)[0]
            line.encoded=False
Ejemplo n.º 2
0
 def decode(cls, line):
     """Remove backslash escaping from line.valueDecode line, either to remove
     backslash espacing, or to decode base64 encoding. The content line should
     contain a ENCODING=b for base64 encoding, but Apple Addressbook seems to
     export a singleton parameter of 'BASE64', which does not match the 3.0
     vCard spec. If we encouter that, then we transform the parameter to
     ENCODING=b"""
     if line.encoded:
         if 'BASE64' in line.singletonparams:
             line.singletonparams.remove('BASE64')
             line.encoding_param = cls.base64string
         encoding = getattr(line, 'encoding_param', None)
         if encoding:
             line.value = line.value.decode('base64')
         else:
             line.value = stringToTextValues(line.value)[0]
         line.encoded=False
Ejemplo n.º 3
0
 def decode(cls, line):
     """Remove backslash escaping from line.valueDecode line, either to remove
     backslash espacing, or to decode base64 encoding. The content line should
     contain a ENCODING=b for base64 encoding, but Apple Addressbook seems to
     export a singleton parameter of 'BASE64', which does not match the 3.0
     vCard spec. If we encouter that, then we transform the parameter to
     ENCODING=b"""
     if line.encoded:
         if 'BASE64' in line.singletonparams:
             line.singletonparams.remove('BASE64')
             line.encoding_param = cls.base64string
         encoding = getattr(line, 'encoding_param', None)
         if encoding:
             line.value = line.value.decode('base64')
         else:
             line.value = stringToTextValues(line.value)[0]
         line.encoded = False
Ejemplo n.º 4
0
def splitFields(string):
    """Return a list of strings or lists from a Name or Address."""
    return [toListOrString(i) for i in
            stringToTextValues(string, listSeparator=';', charList=';')]
Ejemplo n.º 5
0
def toListOrString(string):
    stringList = stringToTextValues(string)
    if len(stringList) == 1:
        return stringList[0]
    else:
        return stringList
Ejemplo n.º 6
0
def splitFields(string):
    """Return a list of strings or lists from a Name or Address."""
    return [
        toListOrString(i)
        for i in stringToTextValues(string, listSeparator=';', charList=';')
    ]
Ejemplo n.º 7
0
def toListOrString(string):
    stringList = stringToTextValues(string)
    if len(stringList) == 1:
        return stringList[0]
    else:
        return stringList