feat: custom address/date parser based on rfc5322 abnf

This commit is contained in:
James Houlahan
2020-10-21 13:37:41 +02:00
parent 9e0635a6a4
commit 3496599723
69 changed files with 20607 additions and 185 deletions

View File

@ -23,12 +23,12 @@ import (
"fmt"
"io"
"net"
"net/mail"
"os"
"strings"
"sync"
"time"
"github.com/ProtonMail/proton-bridge/pkg/message/rfc5322"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -148,12 +148,12 @@ func (c *SMTPClient) SendMail(r io.Reader, bcc string) *SMTPResponse {
from = c.address
if from == "" && strings.HasPrefix(line, "From: ") {
if addr, err := mail.ParseAddress(line[6:]); err == nil {
from = addr.Address
if addrs, err := rfc5322.ParseAddressList(line[6:]); err == nil {
from = addrs[0].Address
}
}
if strings.HasPrefix(line, "To: ") || strings.HasPrefix(line, "CC: ") {
if addrs, err := mail.ParseAddressList(line[4:]); err == nil {
if addrs, err := rfc5322.ParseAddressList(line[4:]); err == nil {
for _, addr := range addrs {
tos = append(tos, addr.Address)
}

View File

@ -19,11 +19,11 @@ package tests
import (
"fmt"
"net/mail"
"strings"
"time"
"github.com/ProtonMail/proton-bridge/internal/store"
"github.com/ProtonMail/proton-bridge/pkg/message/rfc5322"
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
"github.com/ProtonMail/proton-bridge/test/accounts"
"github.com/cucumber/godog"
@ -276,15 +276,15 @@ func messagesContainsMessageRow(account *accounts.TestAccount, allMessages []int
}
func areAddressesSame(first, second string) bool {
firstAddress, err := mail.ParseAddress(first)
firstAddress, err := rfc5322.ParseAddressList(first)
if err != nil {
return false
}
secondAddress, err := mail.ParseAddress(second)
secondAddress, err := rfc5322.ParseAddressList(second)
if err != nil {
return false
}
return firstAddress.Address == secondAddress.Address
return firstAddress[0].Address == secondAddress[0].Address
}
func messagesInMailboxForUserIsMarkedAsRead(bddMessageIDs, mailboxName, bddUserID string) error {

View File

@ -21,13 +21,13 @@ import (
"fmt"
"io"
"io/ioutil"
"net/mail"
"os"
"path/filepath"
"sort"
"strings"
"time"
"github.com/ProtonMail/proton-bridge/pkg/message/rfc5322"
"github.com/cucumber/godog"
"github.com/cucumber/godog/gherkin"
"github.com/emersion/go-mbox"
@ -243,7 +243,7 @@ func parseTime(input string) (time.Time, error) {
}
func parseAddresses(input string) ([]string, error) {
addresses, err := mail.ParseAddressList(input)
addresses, err := rfc5322.ParseAddressList(input)
if err != nil {
return nil, err
}
@ -255,11 +255,11 @@ func parseAddresses(input string) ([]string, error) {
}
func parseAddress(input string) (string, error) {
address, err := mail.ParseAddress(input)
address, err := rfc5322.ParseAddressList(input)
if err != nil {
return "", err
}
return address.Address, nil
return address[0].Address, nil
}
// BySubject implements sort.Interface based on the subject field.