mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-18 08:06:59 +00:00
Fix integration tests - compiting message flags
This commit is contained in:
@ -60,6 +60,7 @@ func GetFlags(m *pmapi.Message) (flags []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ParseFlags(m *pmapi.Message, flags []string) {
|
func ParseFlags(m *pmapi.Message, flags []string) {
|
||||||
|
// Consider to use ComputeMessageFlagsByLabels to keep logic in one place.
|
||||||
if (m.Flags & pmapi.FlagSent) == 0 {
|
if (m.Flags & pmapi.FlagSent) == 0 {
|
||||||
m.Flags |= pmapi.FlagReceived
|
m.Flags |= pmapi.FlagReceived
|
||||||
}
|
}
|
||||||
|
|||||||
@ -839,3 +839,22 @@ func (c *client) EmptyFolder(labelID, addressID string) (err error) {
|
|||||||
err = res.Err()
|
err = res.Err()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ComputeMessageFlagsByLabels returns flags based on labels.
|
||||||
|
func ComputeMessageFlagsByLabels(labels []string) (flag int64) {
|
||||||
|
for _, labelID := range labels {
|
||||||
|
switch labelID {
|
||||||
|
case SentLabel:
|
||||||
|
flag = (flag | FlagSent)
|
||||||
|
case ArchiveLabel, InboxLabel:
|
||||||
|
flag = (flag | FlagReceived)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: if the labels are custom only
|
||||||
|
if flag == 0 {
|
||||||
|
flag = FlagReceived
|
||||||
|
}
|
||||||
|
|
||||||
|
return flag
|
||||||
|
}
|
||||||
|
|||||||
@ -36,6 +36,10 @@ func (ctl *Controller) AddUserMessage(username string, message *pmapi.Message) e
|
|||||||
return fmt.Errorf("user %s does not exist", username)
|
return fmt.Errorf("user %s does not exist", username)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if message.Flags == 0 {
|
||||||
|
message.Flags = pmapi.ComputeMessageFlagsByLabels(message.LabelIDs)
|
||||||
|
}
|
||||||
|
|
||||||
body, err := buildMessage(client, message)
|
body, err := buildMessage(client, message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to build message")
|
return errors.Wrap(err, "failed to build message")
|
||||||
|
|||||||
Reference in New Issue
Block a user