mirror of
https://git.sr.ht/~rjarry/aerc
synced 2025-08-22 19:32:56 +02:00

As part of my effort to properly support labels in IMAP for providers that have this notion, this patch takes care of the case of GMail and Proton, and gracefully errors for all others. To do so, it detects the actual provider we're connected to by analyzing the target URL, and implements label addition / removal (toggling is not supported right now [1]) according to the documentation: - For GMail, it leverages the IMAP STORE command. - For Proton, it leverages moving the message across (virtual) folders. [1] There's nothing fundamental preventing supporting toggling, but getting the current "label state" from there in the code is not trivial. It could be done in a second step if there's demand). Changelog-added: Support :modify-labels command for GMail and Proton. Signed-off-by: Simon Martin <simon@nasilyan.com> Tested-by: Jan Černohorský <jan@grsc.cz> Reviewed-by: Moritz Poldrack <moritz@poldrack.dev> Acked-by: Robin Jarry <robin@jarry.cc>
69 lines
1.2 KiB
Go
69 lines
1.2 KiB
Go
package imap
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestProviderFromURL(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
tests := []struct {
|
|
url string
|
|
provider imapProvider
|
|
}{
|
|
// Positive tests.
|
|
{
|
|
url: "imap.gmail.com",
|
|
provider: GMail,
|
|
},
|
|
{
|
|
url: "127.0.0.1",
|
|
provider: Proton,
|
|
},
|
|
{
|
|
url: "outlook.office365.com",
|
|
provider: Office365,
|
|
},
|
|
{
|
|
url: "imap.zoho.com",
|
|
provider: Zoho,
|
|
},
|
|
{
|
|
url: "imap.fastmail.com",
|
|
provider: FastMail,
|
|
},
|
|
{
|
|
url: "imap.mail.me.com",
|
|
provider: iCloud,
|
|
},
|
|
// Negative tests
|
|
{
|
|
url: "imp.gmail.com",
|
|
provider: Unknown,
|
|
},
|
|
{
|
|
url: "127.0.0.10",
|
|
provider: Unknown,
|
|
},
|
|
{
|
|
url: "outlok.office365.com",
|
|
provider: Unknown,
|
|
},
|
|
{
|
|
url: "imap.zorro.com",
|
|
provider: Unknown,
|
|
},
|
|
{
|
|
url: "imap.slowmail.com",
|
|
provider: Unknown,
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
imapw := &IMAPWorker{}
|
|
assert.Equal(test.provider, imapw.providerFromURL(test.url))
|
|
assert.Equal(test.provider, imapw.providerFromURL(test.url+":1982"))
|
|
assert.Equal(Unknown, imapw.providerFromURL("a"+test.url))
|
|
}
|
|
}
|