Skip to content

Instantly share code, notes, and snippets.

@lithiumfrost
Created February 22, 2023 07:02
Show Gist options
  • Save lithiumfrost/5429469cdd4bc22ab6b1c55626ce578f to your computer and use it in GitHub Desktop.
Save lithiumfrost/5429469cdd4bc22ab6b1c55626ce578f to your computer and use it in GitHub Desktop.
Pull out emails matching critera
#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