def run():

    dataDir = "Data/"
    #ExStart: GetMapiProperty
    # Load from file
    msg = MapiMessage.from_file(dataDir + "message.msg")

    # Access the MapiPropertyTag.PR_SUBJECT property
    prop = msg.properties[MapiPropertyTag.SUBJECT]

    # If the property is not found, check the MapiPropertyTag.PR_SUBJECT_W (which is a // Unicode peer of the MapiPropertyTag.PR_SUBJECT)
    if prop is None:
        prop = msg.properties[MapiPropertyTag.SUBJECT_W]

    # Cannot found
    if prop is None:
        print("No property found!")

    # Get the property data as string
    subject = prop.get_string()

    print("Subject:" + subject)
    # Read internet code page property
    prop = msg.properties[MapiPropertyTag.INTERNET_CPID]
    if prop is not None:
        print("CodePage:" + str(prop.get_long()))
Пример #2
0
def run():
    dataDir = "Data/"
    #ExStart: LoadMsgFiles
    # Create an instance of MapiMessage from file
    msg = MapiMessage.from_file(dataDir +
                                "CreatingAndSavingOutlookMessages_out.msg")

    # Get subject
    print("Subject: " + msg.subject)

    # Get from address
    print("From: " + msg.sender_email_address)

    # Get body
    print("Body: " + msg.body)

    # Get recipients information
    print("Recipients Count: " + str(len(msg.recipients)))

    # Get Attachments information
    print("Attachments Count:" + str(len(msg.attachments)))

    # Print attachments information
    for index, att in enumerate(msg.attachments):
        if att.object_data is not None:
            print(att.display_name)
def run():
	dataDir = "Data/"
	#ExStart: AddingVotingButtonToExistingMessage
	message = MapiMessage.from_file("message.msg")

	FollowUpManager.add_voting_button(message, "Indeed!")

	message.save(dataDir + "AddVotingButtonToExistingMessage_out.msg")
Пример #4
0
def run():
    dataDir = "Data/"
    #ExStart: SetBodyCompression
    eml = MailMessage.load(dataDir +
                           "CreatingAndSavingOutlookMessages_out.msg")
    options = MapiConversionOptions()
    options.use_body_compression = True
    ae_mapi = MapiMessage.from_mail_message(eml, options)
Пример #5
0
def run():
    dataDir = "Data/"
    #ExStart: ReadingOnlyVotingButtons
    message = MapiMessage.from_file(dataDir + "MessageWithVotingResponded.msg")

    buttons = FollowUpManager.get_voting_buttons(message)

    for button in buttons:
        print(button)
Пример #6
0
def run():
    dataDir = "Data/"
    #ExStart: SaveMSGAsTemplate
    # Create an instance of the MapiMessage class
    msg = MapiMessage("*****@*****.**",
                      "[email protected]; [email protected]",
                      "Test Subject", "This is a body of message.")

    msg.save_as_template(dataDir + "SaveMsgAsTemplate_out.msg")
def run():
    dataDir = "Data/"
    #ExStart: ConvertMSGToMimeMessage
    # Create an instance of the MapiMessage class
    msg = MapiMessage("*****@*****.**",
                      "[email protected]; [email protected]",
                      "Test Subject", "This is a body of message.")
    options = MailConversionOptions()
    options.convert_as_tnef = True
    mail = msg.to_mail_message(options)
Пример #8
0
def run():
	dataDir = "Data/"
	#ExStart: PreservingEmbeddedMsgFormat
	eml =  MailMessage.load(dataDir + "sample.eml", EmlLoadOptions())

	options = MapiConversionOptions.unicode_format

	options.preserve_embedded_message_format = True

	# Create an instance of the MapiMessage class and pass MailMessage as argument
	outlookMsg = MapiMessage.from_mail_message(eml, options)
def run():
	dataDir = "Data/"
	#ExStart: AddMessagesToPSTFiles
	pst = PersonalStorage.create(dataDir + "AddMessagesToPst_out.pst", FileFormatVersion.UNICODE)

	# Add new folder "Inbox"
	inboxFolder = pst.root_folder.add_sub_folder("Inbox");

	# Add message to Inbox Folder
	inboxFolder.add_message(MapiMessage.from_file(dataDir + "MapiMsgWithPoll.msg"))

	pst.dispose()
Пример #10
0
def run():
    dataDir = "Data/"
    #ExStart: DeleteVotingButtonFromMessage
    message = MapiMessage.from_file("message.msg")

    FollowUpManager.add_voting_button(message, "Indeed!")

    message.save(dataDir + "AddVotingButtonToExistingMessage_out.msg")

    eml = MailMessage("*****@*****.**", "*****@*****.**", "Subject", "Body")
    eml.is_draft = False
    msg = MapiMessage.from_mail_message(eml)

    options = FollowUpOptions()
    options.voting_buttons = "Yes;No;Maybe;Exactly!"
    FollowUpManager.set_options(msg, options)
    msg.save(dataDir + "MapiMsgWithPoll.msg")
    FollowUpManager.remove_voting_button(msg, "Exactly!")
    #Deleting a single button OR
    FollowUpManager.clear_voting_buttons(
        msg)  # Deleting all buttons from a MapiMessage
    msg.save(dataDir + "MapiMsgWithPoll_out.msg")
Пример #11
0
def run():

	dataDir = "Data/"
	#ExStart: ReadingVotingOptions
	message = MapiMessage.from_file(dataDir + "MessageWithVotingResponded.msg")

	# This method can be useful when except voting buttons it is necessary to get other parameters (ex. a category)
	options = FollowUpManager.get_options(message)

	# Voting buttons will be introduced as a string with semi-column as a separator
	votingButtons = options.voting_buttons

	print(votingButtons)
def run():
	dataDir = "Data/"
	
	#ExStart: CreatingMSGFilesWithRtfBody
	eml = MailMessage()
	eml.is_draft = True

	# Create an instance of the MapiMessage class and pass MailMessage as argument
	outlookMsg = MapiMessage.from_mail_message(eml)

	# Set RTF Body
	outlookMsg.body_rtf = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Calibri;}}\r\n{\\*\\generator Msftedit 5.41.21.2510;}\\viewkind4\\uc1\\pard\\sa200\\sl276\\slmult1\\lang9\\f0\\fs22 This is RTF Body with this \\b bold \\b0 text.\\par\r\n}\r\n\0"
				
	# Save the message (MSG) file
	strMsgFile = "CreatingMSGFilesWithRtfBody_out.msg"
	outlookMsg.save(dataDir + strMsgFile);
Пример #13
0
def run():
    dataDir = "Data/"
    #ExStart: CreatingAndSavingOutlookMSG
    eml = MailMessage()

    # Set from, to, subject and body properties
    eml.from_address = "*****@*****.**"
    eml.to.append("*****@*****.**")
    eml.subject = "This is test message"
    eml.body = "This is test body"

    # Create an instance of the MapiMessage class and pass MailMessage as argument
    outlookMsg = MapiMessage.from_mail_message(eml)

    # Save the message (MSG) file
    strMsgFile = "CreatingAndSavingOutlookMessages_out.msg"
    outlookMsg.save(dataDir + strMsgFile)
def run():

    dataDir = "Data/"
    #ExStart: RenderingContactInformationToMhtml
    msg = MapiMessage.from_file(dataDir + "Contact.msg")
    op = MailConversionOptions()
    eml = msg.to_mail_message(op)

    #Prepare the MHT format options
    mhtSaveOptions = MhtSaveOptions()
    mhtSaveOptions.check_body_content_encoding = True
    mhtSaveOptions.preserve_original_boundaries = True
    formatOp = MhtFormatOptions.WRITE_HEADER | MhtFormatOptions.RENDER_VCARD_INFO
    mhtSaveOptions.rendered_contact_fields = ContactFieldsSet.NAME_INFO | ContactFieldsSet.PERSONAL_INFO | ContactFieldsSet.TELEPHONES | ContactFieldsSet.EVENTS
    mhtSaveOptions.mht_format_options = formatOp
    eml.save(dataDir + "RenderingContactInformationToMhtml_out.mhtml",
             mhtSaveOptions)
def run():
    dataDir = "Data/"
    #ExStart: SavingMessageInDraftStatus
    # Create an instance of the MapiMessage class
    outlookMsg = MapiMessage()

    # Set Message Body
    outlookMsg.body = "Message created with MapiMessage in draft mode."

    #Set the Unsent flag
    outlookMsg.set_message_flags(MapiMessageFlags.UNSENT)

    # Save the message (MSG) file
    strMsgFile = "SavingMessageInDraftStatus_out.msg"
    outlookMsg.save(dataDir + strMsgFile)
def run():
    dataDir = "Data/"
    #ExStart: DraftAppointmentRequest
    #Create Appointment instance
    attendees = MailAddressCollection()
    attendees.append("*****@*****.**")
    app = Appointment("Room 112", dt.datetime(2018, 5, 27, 22, 12, 11), dt.date(2018, 5, 28), "*****@*****.**", attendees);
    app.summary = "Release Meetting";
    app.description = "Discuss for the next release"
    app.method_type = AppointmentMethodType.PUBLISH

    message = MailMessage("*****@*****.**", "*****@*****.**", "", "")

    message.add_alternate_view(app.request_apointment())

    msg = MapiMessage.from_mail_message(message)

    # Save the appointment as draft.
    msg.save(dataDir + "DraftAppointmentRequest_out.msg")
Пример #17
0
def run():

    dataDir = "Data/"
    #ExStart: ReadVoteResultsInformation
    msg = MapiMessage.from_file(dataDir +
                                "AddVotingButtonToExistingMessage.msg")
    for recipient in msg.recipients:
        print("Recipient: {0}".format(recipient.display_name))

        #get the PR_RECIPIENT_AUTORESPONSE_PROP_RESPONSE property
        print("Response: {0}".format(recipient.properties[
            MapiPropertyTag.RECIPIENT_AUTORESPONSE_PROP_RESPONSE].get_string())
              )

        #Get the PR_RECIPIENT_TRACKSTATUS_TIME property
        mt = recipient.properties[MapiPropertyTag.RECIPIENT_TRACKSTATUS_TIME]
        if mt is not None:
            mt_value = mt.get_date_time()
            print("Response time: {}".format(mt_value))
Пример #18
0
def run():
    dataDir = "Data/"
    #ExStart: CreateAppointmentFromString
    ical = """BEGIN:VCALENDAR
    METHOD:PUBLISH
    PRODID:-//Aspose Ltd//iCalender Builder (v3.0)//EN
    VERSION:2.0
    BEGIN:VEVENT
    ATTENDEE;[email protected]:mailto:[email protected]
    DTSTART:20130220T171439
    DTEND:20130220T174439
    DTSTAMP:20130220T161439Z
    END:VEVENT
    END:VCALENDAR"""

    sender = "*****@*****.**"
    recipient = "*****@*****.**"
    message =  MailMessage(sender, recipient, "", "")
    av = AlternateView.create_alternate_view_from_string(ical, ContentType("text/calendar"))
    message.alternate_views.append(av)
    msg = MapiMessage.from_mail_message(message)
    msg.save(dataDir + "draft_out.msg")
Пример #19
0
def run():
    dataDir = "Data/"
    #ExStart: AddingMSGAttachments
    eml = MailMessage()

    # Set from, to, subject and body properties
    eml.from_address = "*****@*****.**"
    eml.to.append("*****@*****.**")
    eml.subject = "This is test message"
    eml.body = "This is test body"

    #Add attachments to MailMessage
    eml.add_attachment(Attachment(dataDir + "1.jpg"))
    eml.add_attachment(Attachment(dataDir + "1.doc"))
    eml.add_attachment(Attachment(dataDir + "1.pdf"))

    # Create an instance of the MapiMessage class and pass MailMessage as argument
    outlookMsg = MapiMessage.from_mail_message(eml)

    # Save the message (MSG) file
    strMsgFile = "AddingMSGAttachments_out.msg"
    outlookMsg.save(dataDir + strMsgFile)
def run():
	dataDir = "Data/"
	#ExStart: LoadingContactFromMSG
	message = MapiMessage.from_file(dataDir + "Contact.msg")

	apiContact = message.to_mapi_message_item()
Пример #21
0
def run():
    dataDir = "Data/"
    #ExStart: ReadingMapiNote
    note = MapiMessage.from_file(dataDir + "CreateAndSaveOutlookNote_out.msg")
    note2 = note.to_mapi_message_item()
Пример #22
0
def main():
    start_time = time.time()

    NrMails = int(17404)
    SavePer = int(40)

    random.seed(8370, version=1)
    rnlist = list()

    Traininglist = pd.DataFrame(columns=['TL1', 'TL2', 'TL3', 'TL4', 'TL5'],
                                index=range(1, 100))

    os.chdir('C:\\Documents\\Test6 Random incl text files')

    Indexlist = pd.read_csv('Index.csv', sep=";", header=None, index_col=0)

    for i in range(1, NrMails + 1):
        if i < 17302:
            msg = MapiMessage.from_file("ENRON (" + str(i) + ").msg")
            sep2 = "EDRM Enron Email Data Set has been produced in"
            msg = msg.body.split(sep2, 1)[0]
            msg = msg.replace('\n', ' ').replace('\r', ' ')

            msg = msg.lower().split(' ')

            for m in range(0, len(msg)):
                for n in set(msg[m]):
                    if ord(n) > 122:
                        msg[m] = msg[m].replace(n, '')
                    elif ord(n) < 97:
                        msg[m] = msg[m].replace(n, '')
            uniqWords = sorted(set(msg))
            uniqWords.remove('')
        else:
            uniqWords = 'test'
        if len(uniqWords) > 0:
            rnlist.append(i)

    for j in ['TL1', 'TL2', 'TL3', 'TL4', 'TL5']:
        for i in range(1, 1625):
            rnumber = random.choice(rnlist)
            Traininglist.at[i, j] = rnumber
            rnlist.remove(rnumber)

    Traininglist.to_csv('TraininglistENRON', sep='\t')

    del i, j, rnumber, rnlist

    start_time2 = time.time()
    Freq = pd.DataFrame(columns=['Index_given'])
    for l in list(Traininglist.columns.values):
        k = 1
        for i in list(Traininglist[l]):
            if i < 17302:
                msg = MapiMessage.from_file("ENRON (" + str(i) + ").msg")

                sep2 = "EDRM Enron Email Data Set has been produced in"
                msg = msg.body.split(sep2, 1)[0]
                msg = msg.replace('\n', ' ').replace('\r', ' ')

                msg = msg.lower().split(' ')

                for m in range(0, len(msg)):
                    for n in set(msg[m]):
                        if ord(n) > 122:
                            msg[m] = msg[m].replace(n, '')
                        elif ord(n) < 97:
                            msg[m] = msg[m].replace(n, '')
                uniqWords = sorted(set(msg))
                uniqWords.remove('')
                df = pd.DataFrame(columns=uniqWords)
                for word in uniqWords:
                    df.at[0, word] = msg.count(word)
            else:
                msg = list()
                with open("ENRON (" + str(i) + ").txt", 'r') as f:
                    lines = f.readlines()
                    for line in lines:
                        line = line.lower().replace('\n',
                                                    ' ').replace('\r',
                                                                 ' ').split()
                        for m in range(0, len(line)):
                            for n in set(line[m]):
                                if ord(n) > 122:
                                    line[m] = line[m].replace(n, '')
                                elif ord(n) < 97:
                                    line[m] = line[m].replace(n, '')
                        for word in line:
                            msg.append(word)
                uniqWords = sorted(set(msg))
                df = pd.DataFrame(columns=uniqWords)
                for word in uniqWords:
                    df.at[0, word] = msg.count(word)

            Freq = Freq.append(df, ignore_index=True)
            if '' in Freq.columns:
                del Freq['']

            j = (k - 1) % SavePer
            Freq.loc[j, 'Index_given'] = Indexlist.loc[i][1]
            if k % SavePer == 0:
                Freq.to_csv('FrequenciesENRON' + l + '-' + str(k), sep='\t')
                Freq = pd.DataFrame(columns=['Index_given'])
                Freq = Freq.take(list())
            k = k + 1
        Freq.to_csv('FrequenciesENRON' + l + '-1640', sep='\t')
        Freq = pd.DataFrame(columns=['Index_given'])
        Freq = Freq.take(list())

    Timings = pd.DataFrame(columns=['Description', 'time'])
    Timings = Timings.append(pd.Series({
        'Description': 'Script',
        'time': time.time() - start_time
    }),
                             ignore_index=True)
    Timings = Timings.append(pd.Series({
        'Description': 'Traininglist',
        'time': time.time() - start_time2
    }),
                             ignore_index=True)
    Timings.to_csv('TimingsENRON-Setup', sep='\t')
Пример #23
0
def run():
	dataDir = "Data/"
	#ExStart: DisplayReceipientsStatusFromMeetingReqeust
	message = MapiMessage.from_file(dataDir + "filename.msg")
	for recipient in message.recipients:
		print(recipient.recipient_track_status)
def run():

    dataDir = "Data/"
    #ExStart: SetMapiProperties
    # Setting MAPI Properties sample
    msg = MapiMessage("*****@*****.**", "*****@*****.**", "This is subject",
                      "This is body")
    msg.set_property(
        MapiProperty(MapiPropertyTag.SENDER_ADDRTYPE, bytes("EX", "utf-8")))

    recipientTo = msg.recipients[0]
    propAddressType = MapiProperty(MapiPropertyTag.RECEIVED_BY_ADDRTYPE,
                                   bytes("MYFAX", "utf-8"))
    recipientTo.set_property(propAddressType)

    faxAddress = "My Fax User@/FN=fax#/VN=voice#/CO=My Company/CI=Local"
    propEmailAddress = MapiProperty(MapiPropertyTag.RECEIVED_BY_EMAIL_ADDRESS,
                                    bytes(faxAddress, "utf-8"))

    recipientTo.set_property(propEmailAddress)

    msg.set_message_flags(MapiMessageFlags.UNSENT | MapiMessageFlags.FROMME)
    msg.set_property(
        MapiProperty(MapiPropertyTag.RTF_IN_SYNC, long_to_mapi_bytes(1)))

    # DateTime property
    modification_date = datetime(2013, 9, 11)
    prop = MapiProperty(MapiPropertyTag.LAST_MODIFICATION_TIME,
                        date_to_mapi_bytes(modification_date))
    msg.set_property(prop)

    msg.save(dataDir + "SetMapiProperties_out.msg")