Skip to content

Commit

Permalink
Store the original email in the emails table.
Browse files Browse the repository at this point in the history
  • Loading branch information
psfblair committed Jun 25, 2014
1 parent 79ac620 commit c91d0cb
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 30 deletions.
2 changes: 1 addition & 1 deletion App/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let loadDataFrom (filename: string) =
let inputString = System.IO.File.ReadAllText(filename)
let message = loadMimeMessageFrom(inputString)
let parseFunction = selectParseFunction filename
let parsed = parseFunction message
let parsed = parseFunction message inputString
loadMail parsed
()

Expand Down
10 changes: 5 additions & 5 deletions DenbowParser/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ let rec calendarEntriesFrom (messageParts: list<MessagePart>) : list<CalendarEnt
| RsvpLinkPart(_) :: items -> calendarEntry :: (calendarEntriesFrom remainingParts)
| _ -> sprintf "Nonempty list not starting with RSVP link part: [%s]" (remainingParts.ToString()) |> failwith

let parseIntoEmailData (sender: string) (sentDate: System.DateTime) (messageParts: list<MessagePart>) : EmailData =
let parseIntoEmailData (sender: string) (sentDate: System.DateTime) (originalMessageString: string) (messageParts: list<MessagePart>) : EmailData =
let intro = messageParts |> extractWithEmptyStringDefault (function | IntroPart(intro) -> Some(String.concat "\n" intro) | _ -> None)
let nonIntroParts = messageParts |> List.filter (function |IntroPart(_) -> false | _ -> true)
let calendarEntries = calendarEntriesFrom nonIntroParts

{ MailDate = sentDate; MailSender = sender; MailIntro = intro; CalendarEntries = calendarEntries }
{ MailDate = sentDate; MailSender = sender; MailIntro = intro; OriginalMessage = originalMessageString; CalendarEntries = calendarEntries }

let parseMail (message: MimeMessage) : EmailData =
let messageData = messageDataFor message
let parseMail (message: MimeMessage) (originalMessageString: string) : EmailData =
let messageData = messageDataFor message originalMessageString
let messageParts = parse messageData.MessageLines PreIntro
parseIntoEmailData messageData.Sender messageData.SentDate messageParts
parseIntoEmailData messageData.Sender messageData.SentDate originalMessageString messageParts
5 changes: 3 additions & 2 deletions DenbowParser/Script.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ open System.Text.RegularExpressions
open DenbowParser.Parser
open DenbowParser.Utils

let message = System.IO.File.ReadAllText("Email.denbow") |> loadMimeMessageFrom
let inputString = System.IO.File.ReadAllText("Email.denbow")
let message = inputString |> loadMimeMessageFrom

let messageData = messageDataFor message
let messageData = messageDataFor message inputString
let messageLines = messageData.MessageLines

let messageParts = parse messageLines PreIntro
Expand Down
5 changes: 3 additions & 2 deletions DenbowParser/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ open EmailParser.Utils.Text
open EmailParser.Utils.Date
open EmailParser.Types

let messageDataFor (message: MimeMessage) =
let messageDataFor (message: MimeMessage) (originalMessageString: string) =
let messageLines = htmlPartsOf message |> String.concat "\n" |> toPlainText |> splitIntoLines
{
Sender = senderOf message;
SentDate = dateOf message;
MessageLines = messageLines
MessageLines = messageLines;
EntireMessage = originalMessageString
}

let startsWithEventDate (line: string) =
Expand Down
10 changes: 5 additions & 5 deletions MeetupParser/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ let calendarEntryFrom (messageParts: seq<MessagePart>) =
RsvpLink = (uriFrom rsvp)
}

let parseIntoEmailData (sender: string) (sentDate: System.DateTime) (messageParts: list<MessagePart>) : EmailData =
let parseIntoEmailData (sender: string) (sentDate: System.DateTime) (originalMessageString: string) (messageParts: list<MessagePart>) : EmailData =
let calendarEntries = [ calendarEntryFrom messageParts ]

{ MailDate = sentDate; MailSender = sender; MailIntro = ""; CalendarEntries = calendarEntries }
{ MailDate = sentDate; MailSender = sender; MailIntro = ""; OriginalMessage = originalMessageString; CalendarEntries = calendarEntries }

let parseMail (message: MimeMessage) : EmailData =
let messageData = messageDataFor message
let parseMail (message: MimeMessage) (originalMessageString: string) : EmailData =
let messageData = messageDataFor message originalMessageString
let messageParts = parse messageData.MessageLines Header
parseIntoEmailData messageData.Sender messageData.SentDate messageParts
parseIntoEmailData messageData.Sender messageData.SentDate originalMessageString messageParts
5 changes: 3 additions & 2 deletions MeetupParser/Script.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ open EmailParser.Utils.Collections
open MeetupParser.Utils
open MeetupParser.Parser

let message = System.IO.File.ReadAllText("Email.meetup") |> loadMimeMessageFrom
let inputString = System.IO.File.ReadAllText("Email.meetup")
let message = inputString |> loadMimeMessageFrom

let messageData = messageDataFor message
let messageData = messageDataFor message inputString
let messageLines = messageData.MessageLines

let message2 = System.IO.File.ReadAllText("Email2.meetup") |> loadMimeMessageFrom
Expand Down
5 changes: 3 additions & 2 deletions MeetupParser/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ open EmailParser.Utils.Date
open EmailParser.Utils.Text
open EmailParser.Types

let messageDataFor (message: MimeMessage) =
let messageDataFor (message: MimeMessage) (originalMessageString: string) =
{
Sender = senderOf message;
SentDate = dateOf message;
MessageLines = (textOf message |> splitIntoLines)
MessageLines = (textOf message |> splitIntoLines);
EntireMessage = originalMessageString
}

let startsWithTitle (line: string) = line.Trim().StartsWith("What:")
Expand Down
10 changes: 5 additions & 5 deletions ODonnellParser/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ let rec calendarEntriesFrom (datePart: MessagePart) (messageParts: list<MessageP
| _ -> sprintf "Nonempty list not starting with date or time part: [%s]" (remainingParts.ToString()) |> failwith


let parseIntoEmailData (sender: string) (sentDate: System.DateTime) (messageParts: list<MessagePart>) : EmailData =
let parseIntoEmailData (sender: string) (sentDate: System.DateTime) (originalMessageString: string) (messageParts: list<MessagePart>) : EmailData =
let intro = messageParts |> extractWithEmptyStringDefault (function | IntroPart(intro) -> Some(String.concat "\n" intro) | _ -> None)
let nonIntroParts = messageParts |> List.filter (function |IntroPart(_) -> false | _ -> true)
let calendarEntries = calendarEntriesFrom nonIntroParts.Head nonIntroParts.Tail

{ MailDate = sentDate; MailSender = sender; MailIntro = intro; CalendarEntries = calendarEntries }
{ MailDate = sentDate; MailSender = sender; MailIntro = intro; OriginalMessage = originalMessageString; CalendarEntries = calendarEntries }

let parseMail (message: MimeMessage) : EmailData =
let messageData = messageDataFor message
let parseMail (message: MimeMessage) (originalMessageString: string) : EmailData =
let messageData = messageDataFor message originalMessageString
let messageParts = parse messageData.MessageLines PreIntro
parseIntoEmailData messageData.Sender messageData.SentDate messageParts
parseIntoEmailData messageData.Sender messageData.SentDate originalMessageString messageParts
5 changes: 3 additions & 2 deletions ODonnellParser/Script.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ open System.Text.RegularExpressions
open ODonnellParser.Parser
open ODonnellParser.Utils

let message = System.IO.File.ReadAllText("Email.odonnell") |> loadMimeMessageFrom
let inputString = System.IO.File.ReadAllText("Email.odonnell")
let message = inputString |> loadMimeMessageFrom

let messageData = messageDataFor message
let messageData = messageDataFor message inputString
let messageParts = parse messageData.MessageLines PreIntro
let nonIntroParts = messageParts |> List.filter (function |IntroPart(_) -> false | _ -> true)
let date = extractDateStringFrom nonIntroParts.Head
Expand Down
5 changes: 3 additions & 2 deletions ODonnellParser/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ open EmailParser.Utils.Date
open EmailParser.Utils.Text
open EmailParser.Types

let messageDataFor (message: MimeMessage) =
let messageDataFor (message: MimeMessage) (originalMessageString: string) =
{
Sender = senderOf message;
SentDate = dateOf message;
MessageLines = (textOf message |> splitIntoLines)
MessageLines = (textOf message |> splitIntoLines);
EntireMessage = originalMessageString
}

let removeEventUrlFrom (eventHeader: string) =
Expand Down
4 changes: 3 additions & 1 deletion ParserTypes/Types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ open System
type EmailMessage = {
Sender: string;
SentDate: DateTime;
MessageLines: list<string>
MessageLines: list<string>;
EntireMessage: string
}

type DateAndTime = {
Expand All @@ -25,5 +26,6 @@ type EmailData = {
MailDate: DateTime;
MailSender: string;
MailIntro: string;
OriginalMessage: string;
CalendarEntries: list<CalendarEntry>
}
1 change: 1 addition & 0 deletions Persistence/SQLitePersistence.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let loadEmailData (dataContext: DataContext) emailData =
email.timestamp <- emailData.MailDate |> secondsSinceEpoch |> Some
email.sender <- emailData.MailSender |> Some
email.intro <- emailData.MailIntro |> Some
email.entire_message <- emailData.OriginalMessage |> Some
dataContext.SubmitUpdates()
email

Expand Down
1 change: 1 addition & 0 deletions Persistence/Script.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let emailData = {
MailDate = System.DateTime.Today;
MailSender = "Charlie O'Donnell <[email protected]>";
MailIntro = "an\nintro";
OriginalMessage = "The Original Message String\n";
CalendarEntries = [calendarEntry; yesterdayEntry]
}

Expand Down
Binary file modified Persistence/events.sqlitedb
Binary file not shown.
3 changes: 2 additions & 1 deletion Persistence/schema.ddl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
date TEXT,
timestamp INTEGER,
sender TEXT,
intro TEXT
intro TEXT,
entire_message TEXT
);

CREATE TABLE calendar_entries(
Expand Down

0 comments on commit c91d0cb

Please sign in to comment.