Skip to content

Commit

Permalink
Mail: Mark as spam: Immediate reaction for user
Browse files Browse the repository at this point in the history
  • Loading branch information
benbucksch committed Aug 30, 2024
1 parent f632f13 commit eff8885
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions app/logic/Mail/EMail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,28 +95,40 @@ export class EMail extends Message {
}

/** Marks as spam, and deletes or moves the message, as configured */
async treatSpam(spam = true) {
async treatSpam(isSpam = true) {
let strategy = this.folder.account.spamStrategy;
if (spam && strategy == DeleteStrategy.DeleteImmediately) {
/** Immediate reaction for end user */
await this.deleteMessageLocally();
}
await this.markSpam(spam);
if (spam && strategy == DeleteStrategy.DeleteImmediately) {
/* The spam flag change might trigger a folder listener
* from the server, which re-adds this message to the local list.
* So, we might have to delete it locally again */
await this.deleteMessage();
} else if (spam && strategy == DeleteStrategy.MoveToTrash) {
let spam = this.folder.account.getSpecialFolder(SpecialFolder.Spam);
assert(spam, gt`Spam folder is not set. Please go to folder properties and set Use As: Spam.`);
spam.moveMessageHere(this);
if (strategy == DeleteStrategy.MoveToTrash) {
let spamFolder = this.folder.account.getSpecialFolder(SpecialFolder.Spam);
assert(spamFolder, gt`Spam folder is not set. Please go to folder properties and set Use As: Spam.`);
if (isSpam) {
/** Immediate reaction for end user */
await this.deleteMessageLocally();
await this.markSpam(isSpam);
spamFolder.moveMessageHere(this);
} else {
await this.markSpam(isSpam);
if (this.folder == spamFolder) {
this.folder.account.inbox.moveMessageHere(this);
}
}
} else if (strategy == DeleteStrategy.DeleteImmediately) {
if (isSpam) {
/** Immediate reaction for end user */
await this.deleteMessageLocally();
await this.markSpam(isSpam);
/* The spam flag change might trigger a folder listener
* from the server, which re-adds this message to the local list.
* So, we might have to delete it locally again */
await this.deleteMessage();
} else {
await this.markSpam(isSpam);
}
}
}

/** You probably want to call @see treatSpam() */
async markSpam(spam = true) {
this.isSpam = spam;
async markSpam(isSpam = true) {
this.isSpam = isSpam;
}

async markReplied() {
Expand Down

0 comments on commit eff8885

Please sign in to comment.