Fix integration tests - compiting message flags

This commit is contained in:
Michal Horejsek 2020-08-17 09:10:03 +02:00
parent 1dcaa200e0
commit 6c93f1f1ec
3 changed files with 24 additions and 0 deletions

View File

@ -60,6 +60,7 @@ func GetFlags(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 {
m.Flags |= pmapi.FlagReceived
}

View File

@ -839,3 +839,22 @@ func (c *client) EmptyFolder(labelID, addressID string) (err error) {
err = res.Err()
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
}

View File

@ -36,6 +36,10 @@ func (ctl *Controller) AddUserMessage(username string, message *pmapi.Message) e
return fmt.Errorf("user %s does not exist", username)
}
if message.Flags == 0 {
message.Flags = pmapi.ComputeMessageFlagsByLabels(message.LabelIDs)
}
body, err := buildMessage(client, message)
if err != nil {
return errors.Wrap(err, "failed to build message")