OpenersPrimaryExamplesSection(Spacer1)Examples  (61)

OpenersExampleSection0(Spacer1)Basic Examples  (4)

Import message summaries for a sample MBOX file:

Import["ExampleData/in.mbox"]

Determine the number of messages in a MBOX file:

Import["ExampleData/conv.mbox","MessageCount"]

Import messages from the MBOX file:

Import["ExampleData/attach.mbox","MessageElements"]

Extract message subjects from a MBOX file:

Import["ExampleData/in.mbox", "Subject"]

Import message dates:

Import["ExampleData/in.mbox", "OriginatingDate"]

OpenersExampleSection1(Spacer1)Scope  (2)

OpenersExampleSubsection0(Spacer1)MBOX Navigation  (2)

Determine the number of messages in the MBOX file:

Import["ExampleData/conv.mbox","MessageCount"]

Import message summaries:

index=Import["ExampleData/in.mbox"]

Extract further information for a particular message using the "MessageID":

Import["ExampleData/in.mbox",{"OriginatingMailClient","<200703141655.l2EGtfL3002494@docex.wolfram.com>"}]

Import a message by its position in the mailbox:

Import["ExampleData/in.mbox",{"MessageElements",2}]

OpenersExampleSection2(Spacer1)Import Elements  (50)

OpenersExampleSubsection1(Spacer1)Available Elements  (1)

List of available elements:

Import["ExampleData/in.mbox","Elements"]

OpenersExampleSubsection2(Spacer1)Data Representation  (11)

OpenersExampleSubsubsection0(Spacer1)"MessageSummaries"  (2)

Get summaries for the messages in the MBOX file:

Import["ExampleData/in.mbox","MessageSummaries"]

View the message summaries as a (RefLink[Dataset, paclet:ref/Dataset]):

Dataset[Import["ExampleData/conv.mbox","MessageSummaries"]]

OpenersExampleSubsubsection1(Spacer1)"MessagesElements"  (2)

Import messages as a list of associations:

Import["ExampleData/in.mbox","MessageElements"]

Import the second message in the MBOX file:

Import["ExampleData/conv.mbox",{"MessageElements",2}]

OpenersExampleSubsubsection2(Spacer1)"FullMessageElements"  (1)

Import the first message in full:

Import["ExampleData/in.mbox",{"FullMessageElements",1}]

OpenersExampleSubsubsection3(Spacer1)"Subject"  (1)

Extract message subjects from an MBOX file:

Import["ExampleData/conv.mbox","Subject"]

OpenersExampleSubsubsection4(Spacer1)"Body"  (1)

Import the message body:

Import["ExampleData/in.mbox","Body"]

OpenersExampleSubsubsection5(Spacer1)"Plaintext"  (1)

Import the first message in its original internet message format:

Import["ExampleData/in.mbox",{"Plaintext",1}]

OpenersExampleSubsubsection6(Spacer1)"BodyPreview"  (2)

Import a summary of new message content:

Import["ExampleData/conv.mbox","BodyPreview"]

"BodyPreview" extracts and summarizes new content in the message:

Import["ExampleData/conv.mbox",{"BodyPreview",6}]

Compare with the full message content:

Import["ExampleData/conv.mbox",{"Body",6}]

OpenersExampleSubsubsection7(Spacer1)"HasAttachments"  (1)

Determine whether a message has an attachment:

Import["ExampleData/in.mbox","HasAttachments"]

OpenersExampleSubsection3(Spacer1)Content Parsing  (2)

OpenersExampleSubsubsection8(Spacer1)"NewBodyContent"  (1)

Extract new unquoted body content from a message:

Import["ExampleData/conv.mbox",{"NewBodyContent",6}]

Compare the extracted content with the original body:

Import["ExampleData/conv.mbox",{"Body",6}]

OpenersExampleSubsubsection9(Spacer1)"QuotedContent"  (1)

Extract quoted content from a message:

Import["ExampleData/conv.mbox",{"QuotedContent",6}]

Compare the extracted content with the original message body:

Import["ExampleData/conv.mbox",{"Body",6}]

OpenersExampleSubsection4(Spacer1)Mail Address Header Elements  (17)

OpenersExampleSubsubsection10(Spacer1)"From"  (1)

Import the sender's name and email address:

Import["ExampleData/conv.mbox","From"]

OpenersExampleSubsubsection11(Spacer1)"FromName"  (1)

Import the sender's full name:

Import["ExampleData/conv.mbox","FromName"]

OpenersExampleSubsubsection12(Spacer1)"FromAddress"  (1)

Import the sender's email address:

Import["ExampleData/conv.mbox","FromAddress"]

OpenersExampleSubsubsection13(Spacer1)"ToList"  (1)

Import a list of recipient names and addresses:

Import["ExampleData/in.mbox","ToList"]

OpenersExampleSubsubsection14(Spacer1)"ToAddressList"  (1)

Import a list of recipient addresses:

Import["ExampleData/in.mbox","ToAddressList"]

OpenersExampleSubsubsection15(Spacer1)"ToNameList"  (1)

Import a list of recipient names:

Import["ExampleData/in.mbox","ToNameList"]

OpenersExampleSubsubsection16(Spacer1)"CcList"  (1)

Import a list of names and addresses for copied recipients:

Import["ExampleData/conv.mbox","CcList"]

OpenersExampleSubsubsection17(Spacer1)"CcAddressList"  (1)

Import a list of addresses for copied recipients:

Import["ExampleData/conv.mbox","CcAddressList"]

OpenersExampleSubsubsection18(Spacer1)"CcNameList"  (1)

Import a list of names for copied recipients:

Import["ExampleData/conv.mbox","CcNameList"]

OpenersExampleSubsubsection19(Spacer1)"BccList"  (1)

Import a list of names and addresses for hidden recipients:

Import["ExampleData/conv.mbox",{"BccList",8}]

OpenersExampleSubsubsection20(Spacer1)"BccAddressList"  (1)

Import a list of addresses for hidden recipients:

Import["ExampleData/conv.mbox",{"BccAddressList",8}]

OpenersExampleSubsubsection21(Spacer1)"BccNameList"  (1)

Import a list of names for hidden recipients:

Import["ExampleData/conv.mbox",{"BccNameList",8}]

OpenersExampleSubsubsection22(Spacer1)"ReturnPath"  (1)

Import the return path:

Import["ExampleData/in.mbox","ReturnPath"]

OpenersExampleSubsubsection23(Spacer1)"ReplyTo"  (1)

Import a list of reply-to names and addresses:

Import["ExampleData/conv.mbox","ReplyTo"]

OpenersExampleSubsubsection24(Spacer1)"ReplyToAddressList"  (1)

Import a list of reply-to addresses:

Import["ExampleData/conv.mbox","ReplyToAddressList"]

OpenersExampleSubsubsection25(Spacer1)"MessageID"  (1)

Retrieve a list of message IDs:

Import["ExampleData/conv.mbox","MessageID"]

OpenersExampleSubsubsection26(Spacer1)"ReplyToMessageID"  (1)

Retrieve the ID of the replied-to message:

Import["ExampleData/conv.mbox","ReplyToMessageID"]

OpenersExampleSubsection5(Spacer1)General Header Elements  (4)

OpenersExampleSubsubsection27(Spacer1)"HeaderString"  (1)

Import the complete mail header of the first message as a string:

Import["ExampleData/in.mbox",{"HeaderString",1}]

OpenersExampleSubsubsection28(Spacer1)"HeaderRules"  (1)

Import the header of the first message as a list of rules:

Import["ExampleData/in.mbox",{"HeaderRules",1}]

OpenersExampleSubsubsection29(Spacer1)"CharacterEncoding"  (1)

Import the character encoding for the first message:

Import["ExampleData/in.mbox",{"CharacterEncoding",1}]

OpenersExampleSubsubsection30(Spacer1)"ContentType"  (1)

Import the MIME content type of the email body:

Import["ExampleData/conv.mbox","ContentType"]

OpenersExampleSubsection6(Spacer1)Advanced Header Elements  (10)

OpenersExampleSubsubsection31(Spacer1)"ReturnReceiptRequested"  (1)

Import any return-receipt addresses:

Import["ExampleData/conv.mbox","ReturnReceiptRequested"]

OpenersExampleSubsubsection32(Spacer1)"DeliveryChainHostnames"  (1)

Import the list of host names in the delivery chain:

Import["ExampleData/conv.mbox",{"DeliveryChainHostnames",1}]

OpenersExampleSubsubsection33(Spacer1)"DeliveryChainRecords"  (1)

Import the delivery chain record as an (RefLink[Association, paclet:ref/Association]):

Import["ExampleData/conv.mbox",{"DeliveryChainRecords",1}]

OpenersExampleSubsubsection34(Spacer1)"OriginatingMailClient"  (1)

Determine the mail client used to send each message:

Import["ExampleData/conv.mbox","OriginatingMailClient"]

OpenersExampleSubsubsection35(Spacer1)"OriginatingIPAddress"  (1)

Import the IP address of the machine used to send a message:

Import["ExampleData/in.mbox","OriginatingIPAddress"]

OpenersExampleSubsubsection36(Spacer1)"OriginatingHostname"  (1)

Import the hostname of the machine used to send a message:

Import["ExampleData/in.mbox","OriginatingHostname"]

OpenersExampleSubsubsection37(Spacer1)"OriginatingDate"  (1)

Import the date and time each message was sent:

Import["ExampleData/in.mbox","OriginatingDate"]

OpenersExampleSubsubsection38(Spacer1)"OriginatingTimezone"  (1)

Import the client time zone from the mail headers:

Import["ExampleData/in.mbox","OriginatingTimezone"]

OpenersExampleSubsubsection39(Spacer1)"ServerOriginatingDate"  (1)

Import the date and time on the originating server:

Import["ExampleData/in.mbox","ServerOriginatingDate"]

OpenersExampleSubsubsection40(Spacer1)"ServerOriginatingTimezone"  (1)

Import the timezone of the originating server:

Import["ExampleData/in.mbox","ServerOriginatingTimezone"]

OpenersExampleSubsection7(Spacer1)Attachment Elements  (5)

OpenersExampleSubsubsection41(Spacer1)"AttachmentSummaries"  (1)

Get summaries for attachments in a particular message:

Import["ExampleData/attach.mbox",{"AttachmentSummaries",1}]

OpenersExampleSubsubsection42(Spacer1)"Attachments"  (1)

Import any attachments as a list of rules:

Import["ExampleData/attach.mbox","Attachments"]

OpenersExampleSubsubsection43(Spacer1)"AttachmentNames"  (1)

Get the file names of any attachments:

Import["ExampleData/attach.mbox","AttachmentNames"]

OpenersExampleSubsubsection44(Spacer1)"AttachmentData"  (1)

Import the raw attachment data of the second message:

Import["ExampleData/in.mbox",{"AttachmentData",2}]

OpenersExampleSubsubsection45(Spacer1)"AttachmentAssociations"  (1)

Import the full attachment data of each message as associations:

Import["ExampleData/attach.mbox","AttachmentAssociations"]

OpenersExampleSection6(Spacer1)Applications  (5)

OpenersExampleSubsection8(Spacer1)Basic Applications  (2)

Import the subject of all messages from "Alice Johnson":

pos=Flatten[Position[Import["ExampleData/conv.mbox",{"FromName"}],"Alice Johnson"]]

Import["ExampleData/conv.mbox",{"Subject",pos}]

Find the position of all messages sent after a particular date:

dates=Import["ExampleData/conv.mbox","OriginatingDate"]

Flatten[Position[dates,d_DateObject/;(d>(DateObject["Thu 12 May 2016 14:00:00""GMT"-5.`, DateObject[{2016,5,12},TimeObject[{14,0,0.`},TimeZone->-5.`],TimeZone->-5.`]]))]]

OpenersExampleSubsection9(Spacer1)Content Parsing  (1)

Find all mentions of the word "lunch" in an MBOX, ignoring quoted content:

Cases[StringCases[#,___~~"lunch"~~___,IgnoreCase->True]&/@Import["ExampleData/conv.mbox","NewBodyContent"],_String,Infinity]

Find all mentions of the word "lunch" in an MBOX, including duplicates in quoted content:

Cases[StringCases[#,___~~"lunch"~~___,IgnoreCase->True]&/@Import["ExampleData/conv.mbox","Body"],_String,Infinity]

OpenersExampleSubsection10(Spacer1)Handling Attachments  (2)

Import messages with attachments larger than 50000 bytes:

maxSize=Max@@Lookup[#,"ByteCount",0]&/@Import["ExampleData/conv.mbox","AttachmentSummaries"]

Import["ExampleData/conv.mbox",{"MessageElements",#}]&/@Flatten[Position[ maxSize,d_/;d>50000]]

Manually import the first attachment of the second message from the raw ASCII-encoded string:

attach=First[Import["ExampleData/in.mbox",{"AttachmentData",2}]];

Lookup[attach,{"ContentTransferEncoding","MIMEType"}]

ImportString[attach["RawContent"],{"Base64","JPEG"}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[MailReceiverFunction, paclet:ref/MailReceiverFunction])}, {Related Formats:  (RefLink[EML, paclet:ref/format/EML])  ▪  (RefLink[ApacheLog, paclet:ref/format/ApacheLog])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Date & Time, paclet:guide/DateAndTime])}, {▪(RefLinkPlain[Importing & Exporting, paclet:guide/ImportingAndExporting])}, {▪(RefLinkPlain[Listing of All Formats, paclet:guide/ListingOfAllFormats])}, {▪(RefLinkPlain[New in 6.0: Data Handling & Data Sources, paclet:guide/NewIn60DataHandlingAndDataSources])}, {▪(RefLinkPlain[New in 6.0: Import & Export Formats, paclet:guide/NewIn60ImportAndExportFormats])}, {▪(RefLinkPlain[Systems & Utility Formats, paclet:guide/SystemsAndUtilityFormats])}})}})