Shared GUI for Bridge and Import/Export

This commit is contained in:
Jakub
2020-05-27 15:58:50 +02:00
committed by Michal Horejsek
parent b598779c0f
commit 49316a935c
96 changed files with 11469 additions and 209 deletions

View File

@ -21,6 +21,8 @@ import (
"crypto/sha256"
"fmt"
"strings"
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
)
// Mailbox is universal data holder of mailbox details for every provider.
@ -36,6 +38,19 @@ func (m Mailbox) Hash() string {
return fmt.Sprintf("%x", sha256.Sum256([]byte(m.Name)))
}
// LeastUsedColor is intended to return color for creating a new inbox or label
func LeastUsedColor(mailboxes []Mailbox) string {
usedColors := []string{}
if mailboxes != nil {
for _, m := range mailboxes {
usedColors = append(usedColors, m.Color)
}
}
return pmapi.LeastUsedColor(usedColors)
}
// findMatchingMailboxes returns all matching mailboxes from `mailboxes`.
// Only one exclusive mailbox is returned.
func (m Mailbox) findMatchingMailboxes(mailboxes []Mailbox) []Mailbox {

View File

@ -23,6 +23,49 @@ import (
r "github.com/stretchr/testify/require"
)
func TestLeastUsedColor(t *testing.T) {
var mailboxes []Mailbox
// Unset mailboxes, should use first available color
mailboxes = nil
r.Equal(t, "#7272a7", LeastUsedColor(mailboxes))
// No mailboxes at all, should use first available color
mailboxes = []Mailbox{}
r.Equal(t, "#7272a7", LeastUsedColor(mailboxes))
// All colors have same frequency, should use first available color
mailboxes = []Mailbox{
{Name: "Mbox1", Color: "#7272a7"},
{Name: "Mbox2", Color: "#cf5858"},
{Name: "Mbox3", Color: "#c26cc7"},
{Name: "Mbox4", Color: "#7569d1"},
{Name: "Mbox5", Color: "#69a9d1"},
{Name: "Mbox6", Color: "#5ec7b7"},
{Name: "Mbox7", Color: "#72bb75"},
{Name: "Mbox8", Color: "#c3d261"},
{Name: "Mbox9", Color: "#e6c04c"},
{Name: "Mbox10", Color: "#e6984c"},
{Name: "Mbox11", Color: "#8989ac"},
{Name: "Mbox12", Color: "#cf7e7e"},
{Name: "Mbox13", Color: "#c793ca"},
{Name: "Mbox14", Color: "#9b94d1"},
{Name: "Mbox15", Color: "#a8c4d5"},
{Name: "Mbox16", Color: "#97c9c1"},
{Name: "Mbox17", Color: "#9db99f"},
{Name: "Mbox18", Color: "#c6cd97"},
{Name: "Mbox19", Color: "#e7d292"},
{Name: "Mbox20", Color: "#dfb286"},
}
r.Equal(t, "#7272a7", LeastUsedColor(mailboxes))
// First three colors already used, but others wasn't. Should use first non-used one.
mailboxes = []Mailbox{
{Name: "Mbox1", Color: "#7272a7"},
{Name: "Mbox2", Color: "#cf5858"},
{Name: "Mbox3", Color: "#c26cc7"},
}
r.Equal(t, "#7569d1", LeastUsedColor(mailboxes))
}
func TestFindMatchingMailboxes(t *testing.T) {
mailboxes := []Mailbox{
{Name: "Inbox", IsExclusive: true},

View File

@ -141,8 +141,8 @@ func (t *Transfer) CreateTargetMailbox(mailbox Mailbox) (Mailbox, error) {
return t.target.CreateMailbox(mailbox)
}
// ChangeTarget allows to change target. Ideally should not be used.
// Useful for situration after user changes mind where to export files and similar.
// ChangeTarget changes the target. It is safe to change target for export,
// must not be changed for import. Do not set after you started transfer.
func (t *Transfer) ChangeTarget(target TargetProvider) {
t.target = target
}