Skip to content

Commit

Permalink
feat(GODT-2201): RFC5322 Rewrite DateTime parser in Go
Browse files Browse the repository at this point in the history
  • Loading branch information
LBeernaertProton committed Feb 21, 2023
1 parent 0259255 commit 37bb6dc
Show file tree
Hide file tree
Showing 5 changed files with 646 additions and 4 deletions.
9 changes: 9 additions & 0 deletions internal/parser/rfc5322_date_time_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package parser

import (
"github.com/ProtonMail/gluon/rfc5322"
"net/mail"
"testing"
"time"
Expand Down Expand Up @@ -247,6 +248,14 @@ func TestParseDateTimeRejected(t *testing.T) {
}

func BenchmarkParseDateTimeGo(B *testing.B) {
input := `Mon, 02 Jan 06 15:04 -0700`
for i := 0; i < B.N; i++ {
_, err := rfc5322.ParseDateTime(input)
require.NoError(B, err)
}
}

func BenchmarkParseDateTimeGoSTD(B *testing.B) {
input := `Mon, 02 Jan 06 15:04 -0700`
for i := 0; i < B.N; i++ {
_, err := mail.ParseDate(input)
Expand Down
8 changes: 4 additions & 4 deletions internal/state/mailbox_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"github.com/ProtonMail/gluon/rfc5322"
"runtime"
"strings"
"sync/atomic"
Expand All @@ -14,7 +15,6 @@ import (
"github.com/ProtonMail/gluon/internal/contexts"
"github.com/ProtonMail/gluon/internal/db"
"github.com/ProtonMail/gluon/internal/db/ent"
"github.com/ProtonMail/gluon/internal/parser"
"github.com/ProtonMail/gluon/rfc822"
"github.com/bradenaw/juniper/parallel"
"github.com/bradenaw/juniper/xslices"
Expand Down Expand Up @@ -575,7 +575,7 @@ func buildSearchOpSentBefore(key *command.SearchKeySentBefore) (*buildSearchOpRe
op := func(s *searchData) (bool, error) {
value := s.header.Get("Date")

date, err := parser.ParseRFC5322DateTime(value)
date, err := rfc5322.ParseDateTime(value)
if err != nil {
return false, err
}
Expand All @@ -594,7 +594,7 @@ func buildSearchOpSentOn(key *command.SearchKeySentOn) (*buildSearchOpResult, er
op := func(s *searchData) (bool, error) {
value := s.header.Get("Date")

date, err := parser.ParseRFC5322DateTime(value)
date, err := rfc5322.ParseDateTime(value)
if err != nil {
return false, err
}
Expand All @@ -614,7 +614,7 @@ func buildSearchOpSentSince(key *command.SearchKeySentSince) (*buildSearchOpResu
op := func(s *searchData) (bool, error) {
value := s.header.Get("Date")

date, err := parser.ParseRFC5322DateTime(value)
date, err := rfc5322.ParseDateTime(value)
if err != nil {
return false, err
}
Expand Down
Loading

0 comments on commit 37bb6dc

Please sign in to comment.