forked from Silverfish/proton-bridge
GODT-1415: Only messages which are in Spam should be moved to INBOX once they are marked as not-a-spam.
This is regression of GODT-963
This commit is contained in:
@ -182,7 +182,7 @@ func (im *imapMailbox) addOrRemoveFlags(operation imap.FlagsOp, messageIDs, flag
|
|||||||
case imap.AnsweredFlag, imap.DraftFlag, imap.RecentFlag:
|
case imap.AnsweredFlag, imap.DraftFlag, imap.RecentFlag:
|
||||||
// Not supported.
|
// Not supported.
|
||||||
case strings.ToLower(message.AppleMailJunkFlag), strings.ToLower(message.ThunderbirdJunkFlag):
|
case strings.ToLower(message.AppleMailJunkFlag), strings.ToLower(message.ThunderbirdJunkFlag):
|
||||||
storeMailbox, err := im.storeAddress.GetMailbox("Spam")
|
spamMailbox, err := im.storeAddress.GetMailbox("Spam")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -191,20 +191,27 @@ func (im *imapMailbox) addOrRemoveFlags(operation imap.FlagsOp, messageIDs, flag
|
|||||||
// No label removal is necessary because Spam and Inbox are both exclusive labels so the backend
|
// No label removal is necessary because Spam and Inbox are both exclusive labels so the backend
|
||||||
// will automatically take care of label removal.
|
// will automatically take care of label removal.
|
||||||
case imap.AddFlags:
|
case imap.AddFlags:
|
||||||
if err := storeMailbox.LabelMessages(messageIDs); err != nil {
|
if err := spamMailbox.LabelMessages(messageIDs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
case imap.RemoveFlags:
|
case imap.RemoveFlags:
|
||||||
// when removing junk flag, the message should be moved to the INBOX folder.
|
// During spam flag removal only messages which
|
||||||
if err := storeMailbox.UnlabelMessages(messageIDs); err != nil {
|
// are in Spam folder should be moved to Inbox.
|
||||||
return err
|
// For other messages it is NOOP.
|
||||||
|
messagesInSpam := []string{}
|
||||||
|
for _, mID := range messageIDs {
|
||||||
|
if uid := spamMailbox.GetUIDList([]string{mID}); len(*uid) != 0 {
|
||||||
|
messagesInSpam = append(messagesInSpam, mID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
inboxMailbox, err := im.storeAddress.GetMailbox("INBOX")
|
if len(messagesInSpam) != 0 {
|
||||||
if err != nil {
|
inboxMailbox, err := im.storeAddress.GetMailbox("INBOX")
|
||||||
return err
|
if err != nil {
|
||||||
}
|
return err
|
||||||
if err := inboxMailbox.LabelMessages(messageIDs); err != nil {
|
}
|
||||||
return err
|
if err := inboxMailbox.LabelMessages(messagesInSpam); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,16 @@ func (api *FakePMAPI) isLabelFolder(labelID string) bool {
|
|||||||
return bool(label.Exclusive)
|
return bool(label.Exclusive)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return labelID == pmapi.InboxLabel || labelID == pmapi.ArchiveLabel || labelID == pmapi.SentLabel
|
switch labelID {
|
||||||
|
case pmapi.InboxLabel,
|
||||||
|
pmapi.TrashLabel,
|
||||||
|
pmapi.SpamLabel,
|
||||||
|
pmapi.ArchiveLabel,
|
||||||
|
pmapi.SentLabel,
|
||||||
|
pmapi.DraftLabel:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *FakePMAPI) ListLabels(context.Context) ([]*pmapi.Label, error) {
|
func (api *FakePMAPI) ListLabels(context.Context) ([]*pmapi.Label, error) {
|
||||||
|
|||||||
@ -20,7 +20,7 @@ Feature: IMAP update messages in Spam folder
|
|||||||
| john.doe@mail.com | user@pm.me | foo |
|
| john.doe@mail.com | user@pm.me | foo |
|
||||||
| jane.doe@mail.com | name@pm.me | bar |
|
| jane.doe@mail.com | name@pm.me | bar |
|
||||||
|
|
||||||
Scenario Outline: Removing flag "junk" or adding flags "nojunk" moves message to INBOX
|
Scenario Outline: Move from Spam to INBOX when client <operation> <flag>
|
||||||
When IMAP client <operation> flags "<flag>" <suffix> message seq "1"
|
When IMAP client <operation> flags "<flag>" <suffix> message seq "1"
|
||||||
Then IMAP response is "OK"
|
Then IMAP response is "OK"
|
||||||
And mailbox "INBOX" for "user" has 1 messages
|
And mailbox "INBOX" for "user" has 1 messages
|
||||||
@ -38,3 +38,25 @@ Feature: IMAP update messages in Spam folder
|
|||||||
| removes | from | junk |
|
| removes | from | junk |
|
||||||
| removes | from | Junk |
|
| removes | from | Junk |
|
||||||
| removes | from | $Junk |
|
| removes | from | $Junk |
|
||||||
|
|
||||||
|
Scenario Outline: Do not move from Archive to INBOX when client <operation> <flag>
|
||||||
|
Given there are messages in mailbox "Archive" for "user"
|
||||||
|
| id | from | to | subject | body | read | starred | deleted |
|
||||||
|
| 1 | john.doe@mail.com | user@pm.me | Archived | hello | false | false | false |
|
||||||
|
And there is IMAP client selected in "Archive"
|
||||||
|
When IMAP client <operation> flags "<flag>" <suffix> message seq "1"
|
||||||
|
Then IMAP response is "OK"
|
||||||
|
And mailbox "INBOX" for "user" has 0 messages
|
||||||
|
And mailbox "Archive" for "user" has 1 messages
|
||||||
|
And mailbox "Archive" for "user" has messages
|
||||||
|
| from | to | subject |
|
||||||
|
| john.doe@mail.com | user@pm.me | Archived |
|
||||||
|
Examples:
|
||||||
|
| operation | suffix | flag |
|
||||||
|
| adds | to | nojunk |
|
||||||
|
| adds | to | NoJunk |
|
||||||
|
| removes | from | junk |
|
||||||
|
| removes | from | Junk |
|
||||||
|
| removes | from | $Junk |
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user