add delete message function
This commit is contained in:
@@ -30,10 +30,17 @@ if (!intro_seen && !request_headers.query.intro_seen) {
|
|||||||
'noback': true,
|
'noback': true,
|
||||||
}).getURL();
|
}).getURL();
|
||||||
|
|
||||||
headers = `200 OK
|
if (request_headers.query.message_delete) {
|
||||||
|
ssid_sessions[socket.ssid].mailstore.deleteMessage(messageid);
|
||||||
|
headers = `300 OK
|
||||||
|
wtv-expire: wtv-mail:/listmail
|
||||||
|
Location: wtv-mail:/listmail`;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
headers = `200 OK
|
||||||
Content-type: text/html`;
|
Content-type: text/html`;
|
||||||
|
|
||||||
data = `<wtvnoscript>
|
data = `<wtvnoscript>
|
||||||
<sendpanel
|
<sendpanel
|
||||||
action = "wtv-mail:/sendmail?message_forward_id=14&mailbox_name=inbox"
|
action = "wtv-mail:/sendmail?message_forward_id=14&mailbox_name=inbox"
|
||||||
message = "Forward this message to someone else."
|
message = "Forward this message to someone else."
|
||||||
@@ -228,18 +235,18 @@ E-mail message
|
|||||||
From:
|
From:
|
||||||
<td width=10>
|
<td width=10>
|
||||||
<td>`;
|
<td>`;
|
||||||
if (message.from_name != message.from_addr) {
|
if (message.from_name != message.from_addr) {
|
||||||
data += `${html_entities.encode(message.from_addr)} <a href="client:showalert?sound=none&message=To%20add%20%3Cblackface%3E${escape(escape(message.from_name))}%3C%2Fblackface%3E%20to%20your%20Address%20book,%20choose%20%3Cb%3EAdd%3C%2Fb%3E.&buttonlabel2=Cancel&buttonaction2=client:donothing&buttonlabel1=Add&buttonaction1=wtv-mail:/addressbook%3Faction%3Deditfromheader%26noresponse%3Dtrue%26nickname%3D${escape(escape(message.from_name))}%26address%3D${escape(escape(message.from_addr))}%26new_address%3Dtrue">(${html_entities.encode(message.from_name)})</a>`;
|
data += `${html_entities.encode(message.from_addr)} <a href="client:showalert?sound=none&message=To%20add%20%3Cblackface%3E${escape(escape(message.from_name))}%3C%2Fblackface%3E%20to%20your%20Address%20book,%20choose%20%3Cb%3EAdd%3C%2Fb%3E.&buttonlabel2=Cancel&buttonaction2=client:donothing&buttonlabel1=Add&buttonaction1=wtv-mail:/addressbook%3Faction%3Deditfromheader%26noresponse%3Dtrue%26nickname%3D${escape(escape(message.from_name))}%26address%3D${escape(escape(message.from_addr))}%26new_address%3Dtrue">(${html_entities.encode(message.from_name)})</a>`;
|
||||||
} else {
|
} else {
|
||||||
data += `${html_entities.encode(message.from_addr)}`;
|
data += `${html_entities.encode(message.from_addr)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
data += `<tr>
|
data += `<tr>
|
||||||
<td valign=top>
|
<td valign=top>
|
||||||
Date:
|
Date:
|
||||||
<td>
|
<td>
|
||||||
<td>
|
<td>
|
||||||
${strftime("%a, %b %e, %Y, %I:%M %P",new Date(message.date * 1000))} (UTC)
|
${strftime("%a, %b %e, %Y, %I:%M %P", new Date(message.date * 1000))} (UTC)
|
||||||
<tr>
|
<tr>
|
||||||
<td valign=top>
|
<td valign=top>
|
||||||
To:
|
To:
|
||||||
@@ -269,6 +276,7 @@ ${(message.signature) ? '<embed src="wtv-mail:/get-signature?message_id=${messag
|
|||||||
</body>
|
</body>
|
||||||
</HTML>
|
</HTML>
|
||||||
`;
|
`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@ class WTVMail {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getMailboxById(mailboxid) {
|
getMailboxById(mailboxid) {
|
||||||
return (mailboxid < this.mailboxes.length - 1) ? this.mailboxes[mailboxid] : false;
|
return (mailboxid < this.mailboxes.length) ? this.mailboxes[mailboxid] : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
getMailboxByName(mailbox_name) {
|
getMailboxByName(mailbox_name) {
|
||||||
@@ -375,31 +375,36 @@ class WTVMail {
|
|||||||
return "Unknown error";
|
return "Unknown error";
|
||||||
}
|
}
|
||||||
|
|
||||||
getMessageMailboxId(messageid) {
|
getMessageMailboxName(messageid) {
|
||||||
// returns the mailbox id of which the message was found for the current user
|
// returns the mailbox id of which the message was found for the current user
|
||||||
var self = this;
|
var self = this;
|
||||||
var mailboxid = false;
|
var mailbox_name = false;
|
||||||
if (this.checkMessageIdSanity(messageid)) {
|
if (this.checkMessageIdSanity(messageid)) {
|
||||||
if (this.mailstoreExists()) {
|
if (this.mailstoreExists()) {
|
||||||
this.fs.readdirSync(this.mailstore_dir).every(mailbox => {
|
this.fs.readdirSync(this.mailstore_dir).every(mailbox => {
|
||||||
if (mailboxid) return false;
|
if (mailbox_name) return false;
|
||||||
self.fs.readdirSync(self.mailstore_dir + mailbox).every(file => {
|
self.fs.readdirSync(self.mailstore_dir + mailbox).every(file => {
|
||||||
var regexSearch = messageid + self.msgFileExt;
|
var regexSearch = messageid + self.msgFileExt;
|
||||||
var re = new RegExp(regexSearch, "ig");
|
var re = new RegExp(regexSearch, "ig");
|
||||||
if (!file.match(re)) return true;
|
if (!file.match(re)) return true;
|
||||||
mailboxid = mailbox;
|
mailbox_name = mailbox;
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mailboxid;
|
return mailbox_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
getMessageMailboxID(messageid) {
|
||||||
|
var mailbox_name = this.getMessageMailboxName(messageid);
|
||||||
|
if (!mailbox_name) return false;
|
||||||
|
return this.getMailboxByName(mailbox_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
getMessageByID(messageid) {
|
getMessageByID(messageid) {
|
||||||
var mailbox_name = this.getMessageMailboxId(messageid);
|
var mailbox_name = this.getMessageMailboxName(messageid);
|
||||||
console.log(mailbox_name);
|
|
||||||
if (!mailbox_name) return false;
|
if (!mailbox_name) return false;
|
||||||
|
|
||||||
var mailboxid = this.mailboxes.findIndex((value) => value == mailbox_name);
|
var mailboxid = this.mailboxes.findIndex((value) => value == mailbox_name);
|
||||||
@@ -410,33 +415,39 @@ class WTVMail {
|
|||||||
|
|
||||||
moveMailMessage(messageid, dest_mailbox_id) {
|
moveMailMessage(messageid, dest_mailbox_id) {
|
||||||
// returns true if successful, false if failed.
|
// returns true if successful, false if failed.
|
||||||
var currentMailbox = getMessageMailboxId(messageid);
|
var currentMailbox = this.getMessageMailboxID(messageid);
|
||||||
|
|
||||||
// Same mailbox
|
// Same mailbox
|
||||||
if (dest_mailbox_id == currentMailbox) return false;
|
if (dest_mailbox_id == currentMailbox) return false;
|
||||||
|
|
||||||
// Invalid destination mailbox ID
|
// Invalid destination mailbox ID
|
||||||
if (dest_mailbox_id > (mailboxes.length - 1) || dest_mailbox_id < 0) return false;
|
if (dest_mailbox_id > (this.mailboxes.length - 1) || dest_mailbox_id < 0) return false;
|
||||||
|
|
||||||
|
if (!this.mailboxExists(dest_mailbox_id)) this.createMailbox(dest_mailbox_id);
|
||||||
|
|
||||||
var currentMailFile = getMailboxStoreDir(currentMailbox) + this.path.sep + messageid + this.msgFileExt;
|
var currentMailStoreDir = this.getMailboxStoreDir(currentMailbox);
|
||||||
var destMailFile = getMailboxStoreDir(dest_mailbox_id) + this.path.sep + messageid + this.msgFileExt;
|
if (!currentMailStoreDir) return false;
|
||||||
|
|
||||||
|
var destMailStoreDir = this.getMailboxStoreDir(dest_mailbox_id);
|
||||||
|
if (!destMailStoreDir) return false;
|
||||||
|
|
||||||
|
var currentMailFile = currentMailStoreDir + this.path.sep + messageid + this.msgFileExt;
|
||||||
|
var destMailFile = destMailStoreDir + this.path.sep + messageid + this.msgFileExt;
|
||||||
|
|
||||||
// File exists
|
// File exists
|
||||||
if (fs.existsSync(destMailFile)) return false;
|
if (this.fs.existsSync(destMailFile)) return false;
|
||||||
|
|
||||||
return fs.rename(currentMailFile, destMailFile);
|
return this.fs.renameSync(currentMailFile, destMailFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteMessage(messageid) {
|
deleteMessage(messageid) {
|
||||||
var currentMailbox = getMessageMailboxId(messageid);
|
var currentMailbox = this.getMessageMailboxName(messageid);
|
||||||
var trashMailbox = getMailboxByName(this.trashMailboxName);
|
var trashMailbox = this.getMailboxByName(this.trashMailboxName);
|
||||||
if (currentMailbox != trashMailbox) {
|
if (currentMailbox != trashMailbox) {
|
||||||
// if not in the trash, move it to trash
|
// if not in the trash, move it to trash
|
||||||
return moveMailMessage(messageid, trashMailbox);
|
return this.moveMailMessage(messageid, trashMailbox);
|
||||||
} else {
|
} else {
|
||||||
// if its already in the trash, delete it forever
|
// if its already in the trash, delete it forever
|
||||||
var currentMailFile = getMailboxStoreDir(trashMailbox) + this.path.sep + messageid + this.msgFileExt;
|
var currentMailFile = this.getMailboxStoreDir(trashMailbox) + this.path.sep + messageid + this.msgFileExt;
|
||||||
if (this.fs.fileExistsSync(currentMailFile))
|
if (this.fs.fileExistsSync(currentMailFile))
|
||||||
return this.fs.unlink(currentMailFile);
|
return this.fs.unlink(currentMailFile);
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user