Esempio n. 1
0
def test_parse_incident_from_item_with_attachments():
    """
    Given:
        - Message item with attachment that contains email attachments

    When:
        - Parsing incident from item

    Verify:
        - Parsing runs successfully
    """
    content = b'ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901;' \
              b' d=microsoft.com; cv=none;b=ES/YXpFlV19rlN1iV+ORg5RzID8GPSQL' \
              b'nUT26MNdeTzcQSwK679doIz5Avpv8Ps2H/aBkBamwRNOCJBkl7iCHyy+04yRj3ghikw3u/ufIFHi0sQ7QG95mO1PVPLibv9A=='

    message = Message(
        datetime_created=EWSDate(year=2021, month=1, day=25),
        to_recipients=[],
        attachments=[
            ItemAttachment(
                item=Item(mime_content=content, headers=[]),
                attachment_id=AttachmentId(),
                last_modified_time=EWSDate(year=2021, month=1, day=25),
            ),
        ],
    )
    incident = parse_incident_from_item(message)
    assert incident['attachment']
Esempio n. 2
0
def test_parse_incident_from_item():
    """
    Given:
        - Message item with attachment that contains non UTF-8 encoded char

    When:
        - Parsing incident from item

    Verify:
        - Parsing runs successfully
        - Incidnet attachment is not empty
    """
    message = Message(
        datetime_created=EWSDate(year=2021, month=1, day=25),
        to_recipients=[],
        attachments=[
            ItemAttachment(
                item=Item(mime_content=b'\xc400'),
                attachment_id=AttachmentId(),
                last_modified_time=EWSDate(year=2021, month=1, day=25),
            ),
        ],
    )
    incident = parse_incident_from_item(message)
    assert incident['attachment']
Esempio n. 3
0
    def test_streaming_file_attachment_error(self):
        # Test that we can parse XML error responses in streaming mode.

        # Try to stram an attachment with malformed ID
        att = FileAttachment(
            parent_item=self.get_test_item(folder=self.test_folder),
            attachment_id=AttachmentId(id='AAMk='),
            name='dummy.txt',
            content=b'',
        )
        with self.assertRaises(ErrorInvalidIdMalformed):
            with att.fp as fp:
                fp.read()

        # Try to stream a non-existent attachment
        att.attachment_id.id = \
            'AAMkADQyYzZmYmUxLTJiYjItNDg2Ny1iMzNjLTIzYWE1NDgxNmZhNABGAAAAAADUebQDarW2Q7G2Ji8hKofPBwAl9iKCsfCfS' \
            'a9cmjh+JCrCAAPJcuhjAABioKiOUTCQRI6Q5sRzi0pJAAHnDV3CAAABEgAQAN0zlxDrzlxAteU+kt84qOM='
        with self.assertRaises(ErrorItemNotFound):
            with att.fp as fp:
                fp.read()
Esempio n. 4
0
    def __init__(self):
        # Get a logger
        log = logging.getLogger(__name__)

        # timestamps the message with current date and time
        time = self.convert_to_EWStime(datetime.now())

        # Create a namedtuple to simulate exchangelib Mailbox object
        FakeSender = namedtuple("FakeSender", ["email_address"])
        my_sender = FakeSender("*****@*****.**")

        self.m = exc.Message(subject="[AM] Test",
                             item_id="DEF568",
                             sender=my_sender,
                             body="Test message",
                             datetime_sent=time)
        log.info('Test message created')
        import os
        cwd = os.path.dirname(os.path.realpath(__file__))
        # filenames = os.listdir(cwd+u"/calcs")
        dummy = os.path.join(cwd, 'calcs', 'Dummy.txt')
        actual = os.path.join(cwd, 'calcs', 'test.xlsx')
        myfiles = [actual]
        for myfile in myfiles:
            try:
                # os.chdir("./calcs")
                log.info("Accessing: %s" % myfile)
                f = open(myfile, mode='rb')
                file_contents = f.read()
                # suffix = random.randint(0,99999)
                att = FileAttachment(name=myfile,
                                     content=file_contents,
                                     attachment_id=AttachmentId())
                self.m.attach(att)
                f.close()
                os.chdir("..")
            except IOError:
                log.error("Error opening file %s. Exiting." % myfile)
                import sys
                sys.exit(0)