Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
EmailParser.Parse
Parses an email.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
EmailParser | 5.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example | Flags |
---|---|---|---|
EmailSource | The source code of an email as text. e.g. as downloaded via IMAP/POP3 functions in CURL. |
$EmailContent | |
Encoding | The text encoding for text parameter. Default is native. Possible encoding names: ANSI, ISO-8859-1, Latin1, Mac, Native, UTF-8, DOS, Hex, Base64 or Windows. More listed in the FAQ. |
UTF8 | Optional |
Result
Returns Reference number or error.
Description
Parses an email.If no error occurs, the parser will separate subject, html and plain text, attachments and inline graphics, all addresses and header entries. You can then use other functions to query values.
If you expect UTF-8 and you have the text in a field already, you may want to pass UTF-8 here for encoding.
If you have EMLX files, please use Text.ReadEMLXFile function first to unpack them and pass the email source to EmailParser.Parse function.
If you need to parse msg files from Outlook, please check the msg-extractor python tool. It can be run via Shell functions to unpack msg files:
https://github.com/TeamMsgExtractor/msg-extractor
Examples
Parse an email and copy data into records:
Set Variable [$email; Value:MBS("EmailParser.Parse"; Email Parser::Input)]
If [MBS("IsError") = 1]
Show Custom Dialog ["Failed to parse email."; Middle($email; 7; Length($email))]
Exit Script []
End If
#Show text:
Set Field [Email Parser::Subject; MBS("EmailParser.Subject"; $email)]
Set Field [Email Parser::PlainText; MBS("EmailParser.PlainText"; $email)]
Set Field [Email Parser::HTMLText; MBS("EmailParser.HTMLText"; $email)]
#find all addresses
Set Variable [$EmailRecordID; Value:Get(RecordID)]
Set Variable [$i; Value:0]
Set Variable [$c; Value:MBS("EmailParser.AddressCount"; $email)]
If [$c > 0]
Go to Related Record [Show only related records; From table: “Address”; Using layout: “Address” (Address)]
Go to Layout [“Address” (Address)]
Delete All Records [No dialog]
Loop
Set Variable [$Name; Value:MBS("EmailParser.Address"; $email; $i; "name")]
Set Variable [$emailAddress; Value:MBS("EmailParser.Address"; $email; $i; "email")]
Set Variable [$type; Value:MBS("EmailParser.Address"; $email; $i; "type")]
New Record/Request
Set Field [Address::Type; $type]
Set Field [Address::Email; $emailAddress]
Set Field [Address::Name; $name]
Set Field [Address::EmailID; $EmailRecordID]
Commit Records/Requests [Skip data entry validation; No dialog]
#next
Set Variable [$i; Value:$i + 1]
Exit Loop If [$i = $c]
End Loop
End If
#find all attachments
Set Variable [$i; Value:0]
Set Variable [$c; Value:MBS("EmailParser.AttachmentCount"; $email)]
If [$c > 0]
Go to Related Record [Show only related records; From table: “Attachment”; Using layout: “Attachment” (Attachment)]
Go to Layout [“Attachment” (Attachment)]
Delete All Records [No dialog]
Loop
Set Variable [$Name; Value:MBS("EmailParser.Attachment"; $email; $i; "filename")]
Set Variable [$content; Value:MBS("EmailParser.Attachment"; $email; $i; "container")]
New Record/Request
Set Field [Attachment::Content; $content]
Set Field [Attachment::FileName; $name]
Set Field [Attachment::EmailID; $EmailRecordID]
Commit Records/Requests [Skip data entry validation; No dialog]
#next
Set Variable [$i; Value:$i + 1]
Exit Loop If [$i = $c]
End Loop
End If
#find all inline graphics
Set Variable [$i; Value:0]
Set Variable [$c; Value:MBS("EmailParser.InlineCount"; $email)]
If [$c > 0]
Go to Related Record [Show only related records; From table: “InlineGraphics”; Using layout: “InlineGraphics” (InlineGraphics)]
Go to Layout [“InlineGraphics” (InlineGraphics)]
Delete All Records [No dialog]
Loop
Set Variable [$Name; Value:MBS("EmailParser.Inline"; $email; $i; "filename")]
Set Variable [$content; Value:MBS("EmailParser.Inline"; $email; $i; "container")]
New Record/Request
Set Field [InlineGraphics::Content; $content]
Set Field [InlineGraphics::FileName; $name]
Set Field [InlineGraphics::EmailID; $EmailRecordID]
Commit Records/Requests [Skip data entry validation; No dialog]
#next
Set Variable [$i; Value:$i + 1]
Exit Loop If [$i = $c]
End Loop
End If
Go to Layout [original layout]
#find a header
Set Variable [$i; Value:0]
Set Variable [$c; Value:MBS("EmailParser.HeaderCount"; $email)]
If [$c > 0]
Loop
Set Variable [$HeaderName; Value:MBS("EmailParser.Header"; $email; $i; "name")]
If [$HeaderName = "X-Mailer"]
Set Variable [$HeaderValue; Value:MBS("EmailParser.Header"; $email; $i; "value")]
Set Field [Email Parser::Mailer; $HeaderValue]
End If
#next
Set Variable [$i; Value:$i + 1]
Exit Loop If [$i = $c]
End Loop
End If
#cleanup
Set Variable [$r; Value:MBS("EmailParser.Release"; $email)]
Extract email text:
Set Variable [$EmailID; Value:MBS( "EmailParser.Parse"; email::raw)]
Set Field [email::raw_plainText; MBS( "EmailParser.PlainText"; $EmailID )]
Set Field [email::raw_htmltext; MBS( "EmailParser.HTMLText"; $EmailID )]
Set Variable [$r; Value:MBS( "EmailParser.Release"; $EmailID)]
Read emlx file:
# emlx test in file Contacts
Set Variable [ $path ; Value: "/Users/cs/Desktop/28213.emlx" ]
Set Variable [ $emailSourceText ; Value: MBS( "Text.ReadEMLXFile"; $path; "UTF-8") ]
If [ MBS("IsError") = 0 ]
Set Variable [ $email ; Value: MBS( "EmailParser.Parse"; $EmailSourceText; "UTF8") ]
If [ MBS("IsError") = 0 ]
Show Custom Dialog [ "Email subject" ; MBS( "EmailParser.Subject"; $email ) ]
Set Variable [ $r ; Value: MBS( "EmailParser.Release"; $email ) ]
End If
End If
See also
- EmailParser.Hash
- EmailParser.List
- EmailParser.ParseContainer
- EmailParser.ParseFile
- EmailParser.PlainText
- EmailParser.Release
- EmailParser.Source
- EmailParser.Subject
- IsError
- Text.ReadEMLXFile
Release notes
- Version 12.0
- Fixed a problem in email parser, which didn't get multi part right on Linux for EmailParser.Parse, EmailParser.ParseContainer and EmailParser.ParseFile.
- Version 9.4
- Fixed bug in EmailParser.Parse where html text sometimes contained an extra = on the end.
Example Databases
Blog Entries
- MBS Plugin Advent calendar: 23 - MailParser
- MBS FileMaker Plugin, version 11.6pr3
- MBS FileMaker Plugin, version 9.4pr1
This function is free to use.
Created 24th September 2015, last changed 21st August 2024