Example #1
0
def ParseContent(source, content_type='application/dime'):  # noqa
    """
    Parse the content and return a decode stream
    """
    if content_type == 'application/dime':
        if Message is None:
            raise Exception('error', 'python dime package is not installed!')
        fp = StringIO(source)
        a = Message.load(fp)
        content = ''
        for x in a.records:
            if x.type.value == 'application/pdf':
                content = x.data
        return content
    elif content_type.startswith('multipart/related'):
        srch = re.search(r'----=[^\r\n]*', source)
        if srch is None:
            raise NotMultipartError()
        boundary = srch.group()
        res = " \n" + source
        res = "Content-Type: multipart/alternative; boundary=%s\n%s" % (
            boundary, res)  # noqa
        message = email.message_from_string(res)
        attachment = message.get_payload()[1]
        return attachment.get_payload()
    else:
        raise Exception('Unknown Content Type')
def ParseContent(source):
    """
    Parse the content and return a decode stream

    """
    fp = StringIO(source)
    a = Message.load(fp)
    content = ''
    for x in a.records:
        if x.type.value.startswith('application'):
            content = x.data
    return content
Example #3
0
def ParseContent(source):
    """
    Parse the content and return a decode stream

    """
    fp = StringIO(source)
    a = Message.load(fp)
    content = ''
    for x in a.records:
        if x.type.value == 'application/pdf':
            content = x.data
    return content
Example #4
0
def ParseDIME(source, list_file):
    """
    We must decompose the dime record to return the PDF only
    """
    fp = StringIO(source)
    a = Message.load(fp)
    for x in a.records:
        if x.type.value == 'application/pdf':
            content = x.data
            # Store the PDF in TEMP directory
            __, f_name = mkstemp(suffix='.pdf', prefix='jasper')
            list_file.append(f_name)
            fpdf = open(f_name, 'w+b')
            fpdf.write(content)
            fpdf.close()
Example #5
0
def ParseDIME(source, list_file):
    """
    We must decompose the dime record to return the PDF only
    """
    fp = StringIO(source)
    a = Message.load(fp)
    for x in a.records:
        if x.type.value == 'application/pdf':
            content = x.data
            # Store the PDF in TEMP directory
            fd, f_name = mkstemp(suffix='.pdf', prefix='jasper')
            list_file.append(f_name)
            fpdf = open(f_name, 'w+b')
            fpdf.write(content)
            fpdf.close()
            os.close(fd)
def ParseContent(source, content_type='application/dime'):
    """
    Parse the content and return a decode stream
    """
    if content_type == 'application/dime':
        fp = StringIO(source)
        a = Message.load(fp)
        content = ''
        for x in a.records:
            if x.type.value == 'application/pdf':
                content = x.data
        return content
    elif content_type.startswith('multipart/related'):
        srch = re.search(r'----=[^\r\n]*', source)
        if srch is None:
            raise NotMultipartError()
        boundary = srch.group()
        res = " \n" + source
        res = "Content-Type: multipart/alternative; boundary=%s\n%s" % (boundary, res)
        message = email.message_from_string(res)
        attachment = message.get_payload()[1]
        return attachment.get_payload()
    else:
        raise Exception('Unknown Content Type')