mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-17 23:56:56 +00:00
feat: custom address/date parser based on rfc5322 abnf
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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.
|
||||
|
||||
Reference in New Issue
Block a user