Created
February 22, 2023 07:02
-
-
Save lithiumfrost/5429469cdd4bc22ab6b1c55626ce578f to your computer and use it in GitHub Desktop.
Pull out emails matching critera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "nuget:MimeKit" | |
open System.IO | |
open System.Text.RegularExpressions | |
open MimeKit | |
let (=~) (input: InternetAddressList) pattern = | |
input | |
|> Seq.exists (fun addr -> | |
let m = | |
Regex.Match((addr :?> MailboxAddress).Address, pattern, RegexOptions.IgnoreCase) in | |
if m.Success then true else false) | |
let parse (parser: MimeParser) = | |
try | |
Some(parser.ParseMessage()) | |
with _ -> | |
None | |
let getWilliamsFiles mailbox = | |
use stream = File.Open(mailbox, FileMode.Open) | |
let parser = MimeParser(stream, MimeFormat.Mbox) | |
seq { | |
while not parser.IsEndOfStream do | |
yield (parse parser) | |
} | |
|> Seq.choose id | |
|> Seq.filter (fun x -> x.From =~ "example.com" || x.To =~ "example.com") | |
|> Seq.take 3 | |
|> Seq.iter (printfn "%A") | |
getWilliamsFiles | |
@"B:\inbox.mbox" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment