fix could not send mail (for real this time)

This commit is contained in:
zefie
2025-08-08 23:33:03 -04:00
parent 8760979242
commit 4105300f1b
2 changed files with 33 additions and 12 deletions

View File

@@ -176,7 +176,9 @@ Content-Type: audio/wav`;
attachments.push(attachment); attachments.push(attachment);
} }
console.log("DEBUG sendmail: Before send decision - newsgroup =", newsgroup, "to_addr =", to_addr);
if (newsgroup !== null) { if (newsgroup !== null) {
console.log("DEBUG sendmail: Taking newsgroup path");
var request_is_async = true; var request_is_async = true;
var local_service_name = request_headers.query['discuss-prefix'] || "wtv-news" var local_service_name = request_headers.query['discuss-prefix'] || "wtv-news"
const wtvnews = new WTVNews(minisrv_config, local_service_name); const wtvnews = new WTVNews(minisrv_config, local_service_name);
@@ -268,6 +270,7 @@ Location: wtv-news:/news?group=${newsgroup}`;
} else { } else {
console.log("DEBUG sendmail: Taking email path with to_addr =", to_addr);
var messagereturn = session_data.mailstore.sendMessageToAddr(from_addr, to_addr, msg_body, msg_subject, userdisplayname, to_name, signature, attachments, msg_url, msg_url_title); var messagereturn = session_data.mailstore.sendMessageToAddr(from_addr, to_addr, msg_body, msg_subject, userdisplayname, to_name, signature, attachments, msg_url, msg_url_title);
if (messagereturn !== true) { if (messagereturn !== true) {
var errpage = wtvshared.doErrorPage(400, messagereturn); var errpage = wtvshared.doErrorPage(400, messagereturn);

View File

@@ -97,12 +97,13 @@ class WTVMail {
mailboxExists(mailboxid) { mailboxExists(mailboxid) {
if (mailboxid >= this.mailboxes.length) return null; if (mailboxid >= this.mailboxes.length) return null;
var mailbox_dir = null; var mailbox_dir = null;
var store_dir = null;
if (this.mailstoreExists()) { if (this.mailstoreExists()) {
var mailbox_name = this.getMailboxById(mailboxid); var mailbox_name = this.getMailboxById(mailboxid);
if (!mailbox_name) return null; if (!mailbox_name) return null;
var mailbox_dir = mailbox_name + this.path.sep; mailbox_dir = mailbox_name + this.path.sep;
var store_dir = this.mailstore_dir + mailbox_dir; store_dir = this.mailstore_dir + mailbox_dir;
} }
return (store_dir !== null) ? this.fs.existsSync(store_dir) : false; return (store_dir !== null) ? this.fs.existsSync(store_dir) : false;
} }
@@ -181,22 +182,25 @@ class WTVMail {
} }
try { try {
if (this.fs.existsSync(message_file_out)) { if (this.fs.existsSync(message_file_out)) {
console.error(" * ERROR: Message with this UUID (" + messageid + ") already exists (should never happen). Message lost."); console.error(" * ERROR: Message with this UUID (" + message_id + ") already exists (should never happen). Message lost.");
return false; return false;
} }
// encode message into json // encode message into json
var result = this.fs.writeFileSync(message_file_out, JSON.stringify(message_data)); this.fs.writeFileSync(message_file_out, JSON.stringify(message_data));
if (!result) return false;
// rely on filesystem times for sorting as it is quicker then reading every file // Skip timestamp setting for now as it's causing issues with malformed paths
var file_timestamp = new Date(date * 1000); // var file_timestamp = new Date(date * 1000);
fs.utimesSync(message_file, Date.now(), file_timestamp); // this.fs.utimesSync(message_file_out, Date.now(), file_timestamp);
if (!result) console.error(" WARNING: Setting timestamp on " + message_file + " failed, mail dates will be inaccurate.");
return true; // Success!
} catch (e) { } catch (e) {
console.error(" # MailErr: Mail Store failed\n", e, "\n", message_file_out, "\n", message_data ,"\n"); console.error(" # MailErr: Mail Store failed\n", e, "\n", message_file_out, "\n", message_data ,"\n");
return false;
} }
} else {
console.error("DEBUG: createMailbox failed for mailboxid:", mailboxid);
return false; return false;
} }
} }
@@ -391,8 +395,17 @@ class WTVMail {
if (temp_session_data.subscriber_username.toLowerCase() == username.toLowerCase()) { if (temp_session_data.subscriber_username.toLowerCase() == username.toLowerCase()) {
// Use the absolute path for replacement since search_dir is now absolute // Use the absolute path for replacement since search_dir is now absolute
var accounts_dir = self.wtvshared.getAbsolutePath(self.minisrv_config.config.SessionStore + self.path.sep + "accounts" + self.path.sep); var accounts_dir = self.wtvshared.getAbsolutePath(self.minisrv_config.config.SessionStore + self.path.sep + "accounts" + self.path.sep);
return_val = search_dir.replace(accounts_dir, '').replace("user", '').split(self.path.sep); var path_after_replace = search_dir.replace(accounts_dir, '');
return_val.push(temp_session_data.subscriber_name); // Remove leading path separator if present
if (path_after_replace.startsWith(self.path.sep)) {
path_after_replace = path_after_replace.substring(1);
}
var path_split = path_after_replace.split(self.path.sep);
// The path should be like "ssid/user0", so extract ssid and user_id
var ssid = path_split[0];
var user_part = path_split[1] || '';
var user_id = user_part.replace('user', '');
return_val = [ssid, user_id, temp_session_data.subscriber_name];
} }
} }
} catch (e) { } catch (e) {
@@ -445,7 +458,12 @@ class WTVMail {
if (mailbox_exists) dest_user_mailstore.createWelcomeMessage(); if (mailbox_exists) dest_user_mailstore.createWelcomeMessage();
} }
// if the mailbox exists, deliver the message // if the mailbox exists, deliver the message
if (dest_user_mailstore.mailboxExists(0)) dest_user_mailstore.createMessage(0, from_addr, to_addr, msgbody, subject, from_name, to_name, signature, null, this.isInUserAddressBook(to_addr, from_addr), attachments, url, url_title); if (dest_user_mailstore.mailboxExists(0)) {
var createResult = dest_user_mailstore.createMessage(0, from_addr, to_addr, msgbody, subject, from_name, to_name, signature, null, this.isInUserAddressBook(to_addr, from_addr), attachments, url, url_title);
if (!createResult) {
return "There was an error creating the message in the recipient's mailbox.";
}
}
else return "There was an internal error sending the message to <strong>" + to_addr + "</strong>. Please try again later"; else return "There was an internal error sending the message to <strong>" + to_addr + "</strong>. Please try again later";
// clean up // clean up