jcs
/subtext
/amendments
/384
mail: Get rid of fidonet pending dispatch stuff
At save time, create a fidopkt and hand it to binkp for saving
jcs made amendment 384 about 1 year ago
--- db.h Mon Mar 6 16:34:35 2023
+++ db.h Wed Mar 8 17:16:09 2023
@@ -50,18 +50,20 @@
#define SL_LOG_RTYPE 'SLOG'
#define SL_TALLY_RTYPE 'STLY'
-#define BOARD_FILENAME_EXT "brd"
-#define BOARD_THREAD_RTYPE 'BDTH'
-#define BOARD_POST_RTYPE 'BDPS'
-#define BOARD_FIDONET_POST_RTYPE 'BDFP'
-#define BOARD_FIDONET_MSGID_CACHE_RTYPE 'BDMC'
-#define BOARD_SORTED_IDS_RTYPE 'BDDX'
+#define BOARD_FILENAME_EXT "brd"
+#define BOARD_THREAD_RTYPE 'BDTH'
+#define BOARD_POST_RTYPE 'BDPS'
+#define BOARD_FIDONET_POST_RTYPE 'BDFP'
+#define BOARD_FIDONET_MSGID_CACHE_RTYPE 'BDMC'
+#define BOARD_SORTED_IDS_RTYPE 'BDDX'
-#define FOLDER_FILENAME_EXT "fld"
-#define FOLDER_FILE_RTYPE 'FILE'
+#define FOLDER_FILENAME_EXT "fld"
+#define FOLDER_FILE_RTYPE 'FILE'
-#define MAIL_SPOOL_TYPE 'STMS'
-#define MAIL_SPOOL_MESSAGE_RTYPE 'PMSG'
+#define MAIL_SPOOL_TYPE 'STMS'
+#define MAIL_SPOOL_MESSAGE_RTYPE 'PMSG'
+
+#define FIDONET_SPOOL_PACKET_TYPE 'FNSP'
#include "subtext.h"
#include "bile.h"
--- mail.c Tue Mar 7 22:47:27 2023
+++ mail.c Thu Mar 9 10:06:11 2023
@@ -20,6 +20,7 @@
#include <string.h>
#include "ansi.h"
+#include "binkp.h"
#include "logger.h"
#include "mail.h"
#include "subtext.h"
@@ -70,8 +71,6 @@ static const struct bile_object_field mail_object_fiel
member_size(struct mail_message, fidonet_msgid_orig), -1 },
{ offsetof(struct mail_message, fidonet_reply),
member_size(struct mail_message, fidonet_reply), -1 },
- { offsetof(struct mail_message, fidonet_need_dispatch),
- member_size(struct mail_message, fidonet_need_dispatch), -1 },
};
static const size_t nmail_object_fields = nitems(mail_object_fields);
@@ -256,7 +255,9 @@ mail_compose(struct session *s, char *initial_to, char
{
struct user *to_user = NULL;
struct mail_message msg = { 0 };
- struct fidopkt_address *fidonet_to = NULL;
+ struct fidopkt_address *fidonet_our_address = NULL,
+ *fidonet_to = NULL;
+ struct fidopkt pkt = { 0 };
char *to_username = NULL, *tmp, *at;
char c;
@@ -266,6 +267,9 @@ mail_compose(struct session *s, char *initial_to, char
session_flush(s);
return;
}
+
+ fidopkt_parse_address(db->config.fidonet_node_addr,
+ &fidonet_our_address);
if (initial_to) {
to_username = xstrdup(initial_to);
@@ -303,6 +307,14 @@ mail_compose_start:
}
if ((at = strstr(to_username, "@")) != NULL) {
+ if (fidonet_our_address == NULL) {
+ session_printf(s, "\r\n{{B}}Error:{{/B}}{{#}} FidoNet "
+ "mail is not supported at this time.\r\n");
+ session_flush(s);
+ xfree(&to_username);
+ continue;
+ }
+
if (!fidopkt_parse_address(at + 1, &fidonet_to)) {
session_printf(s, "\r\n{{B}}Error:{{/B}}{{#}} Invalid "
"FidoNet destination \"%s\" (^C to cancel)\r\n", at + 1);
@@ -317,7 +329,6 @@ mail_compose_start:
at[0] = '\0';
strlcpy(msg.fidonet_from, s->user->username,
sizeof(msg.fidonet_from));
- msg.fidonet_need_dispatch = 1;
session_printf(s, " (FidoNet)\r\n");
session_flush(s);
} else {
@@ -333,7 +344,6 @@ mail_compose_start:
}
msg.recipient_user_id = to_user->id;
xfree(&to_user);
- msg.fidonet_need_dispatch = 0;
}
break;
}
@@ -398,7 +408,7 @@ mail_compose_start:
for (;;) {
session_printf(s, "\r\n{{B}}(S){{/B}}end %smessage, "
"{{B}}(E){{/B}}dit again, or {{B}}(C){{/B}}ancel? ",
- msg.fidonet_need_dispatch ? "FidoNet " : "");
+ msg.fidonet_to[0] ? "FidoNet " : "");
session_flush(s);
c = session_input_char(s);
@@ -420,7 +430,7 @@ mail_compose_start:
case '\n':
case '\r':
/* send */
- if (msg.fidonet_need_dispatch)
+ if (msg.fidonet_to[0])
session_printf(s, "Queueing mail for FidoNet delivery...");
else
session_printf(s, "Sending mail...");
@@ -429,19 +439,47 @@ mail_compose_start:
msg.time = Time;
msg.sender_user_id = s->user->id;
- if (fidonet_reply_msgid != NULL && fidonet_reply_msgid[0])
- strlcpy(msg.fidonet_reply, fidonet_reply_msgid,
- sizeof(fidonet_reply_msgid));
+ msg.id = bile_next_id(db->mail_bile,
+ MAIL_SPOOL_MESSAGE_RTYPE);
+ if (msg.fidonet_to[0]) {
+ if (fidonet_reply_msgid != NULL && fidonet_reply_msgid[0])
+ strlcpy(msg.fidonet_reply, fidonet_reply_msgid,
+ sizeof(fidonet_reply_msgid));
+
+ msg.fidonet_msgid.id = msg.id;
+ msg.fidonet_msgid.zone = fidonet_our_address->zone;
+ msg.fidonet_msgid.net = fidonet_our_address->net;
+ msg.fidonet_msgid.node = fidonet_our_address->node;
+ msg.fidonet_msgid.point = fidonet_our_address->point;
+ }
+
if (mail_save(&msg) != 0) {
session_printf(s, "failed!\r\n");
session_flush(s);
break;
}
- if (msg.fidonet_need_dispatch)
+ if (msg.fidonet_to[0]) {
+ pkt.time = msg.time;
+ memcpy(&pkt.orig, fidonet_our_address, sizeof(pkt.orig));
+ pkt.dest = msg.fidonet_dest;
+ strlcpy(pkt.to, msg.fidonet_to, sizeof(pkt.to));
+ strlcpy(pkt.from, msg.fidonet_from, sizeof(pkt.from));
+ strlcpy(pkt.subject, msg.subject, sizeof(pkt.subject));
+ pkt.body = msg.body;
+ pkt.body_len = msg.body_size;
+ if (fidonet_reply_msgid != NULL && fidonet_reply_msgid[0])
+ strlcpy(pkt.reply, fidonet_reply_msgid,
+ sizeof(pkt.reply));
+ pkt.msgid = msg.fidonet_msgid;
+ if (!binkp_store_outbound_fidopkt(&pkt)) {
+ session_printf(s, "failed!\r\n");
+ session_flush(s);
+ break;
+ }
session_printf(s, " done!\r\n");
- else
+ } else
session_printf(s, " sent!\r\n");
session_flush(s);
@@ -460,6 +498,10 @@ mail_compose_start:
mail_compose_done:
if (to_username != NULL)
xfree(&to_username);
+
+ if (fidonet_our_address != NULL)
+ xfree(&fidonet_our_address);
+
mail_free_message_strings(&msg);
}
@@ -875,8 +917,8 @@ mail_ingest_fidopkt(struct fidopkt *fidopkt)
msg.time = Time;
msg.subject = xstrdup(fidopkt->subject);
msg.subject_size = strlen(msg.subject) + 1;
- msg.body = fidopkt->message;
- msg.body_size = fidopkt->message_len + 1;
+ msg.body = fidopkt->body;
+ msg.body_size = fidopkt->body_len + 1;
msg.fidonet_msgid = fidopkt->msgid;
msg.fidonet_orig = fidopkt->orig;
@@ -905,125 +947,4 @@ done:
xfree(&to);
xfree(&our_address);
return ret;
-}
-
-size_t
-mail_ids_needing_fidonet_dispatch(unsigned long **ids)
-{
- struct mail_message msg;
- size_t nmail_ids, nall_mail_ids, mail_ids_size, size, n;
- unsigned long *mail_ids = NULL, *all_mail_ids = NULL;
- char *data;
- bool failed = false;
-
- *ids = NULL;
-
- nall_mail_ids = bile_ids_by_type(db->mail_bile,
- MAIL_SPOOL_MESSAGE_RTYPE, &all_mail_ids);
-
- if (nall_mail_ids == 0)
- return 0;
-
- mail_ids_size = 0;
- nmail_ids = 0;
- for (n = 0; n < nall_mail_ids; n++) {
- size = bile_read_alloc(db->mail_bile, MAIL_SPOOL_MESSAGE_RTYPE,
- all_mail_ids[n], &data);
- if (size == 0) {
- failed = true;
- goto done;
- }
- bile_unmarshall_object(db->mail_bile, mail_object_fields,
- nitems(mail_object_fields), data, size, &msg, sizeof(msg),
- false);
- xfree(&data);
- if (!msg.fidonet_need_dispatch)
- continue;
-
- if (!grow_to_fit(&mail_ids, &mail_ids_size,
- (nmail_ids + 1) * sizeof(long), sizeof(long),
- sizeof(long) * 16)) {
- failed = true;
- goto done;
- }
- mail_ids[nmail_ids] = all_mail_ids[n];
- nmail_ids++;
- }
-
-done:
- xfree(&all_mail_ids);
- if (failed) {
- if (mail_ids != NULL)
- xfree(&mail_ids);
- return 0;
- }
- *ids = mail_ids;
- return nmail_ids;
-}
-
-size_t
-mail_encode_as_fidopkt(unsigned long id, struct fidopkt_address *orig_node,
- char **pkt_buf)
-{
- struct mail_message msg;
- size_t size;
- char *data;
- short ret;
-
- *pkt_buf = NULL;
-
- size = bile_read_alloc(db->mail_bile, MAIL_SPOOL_MESSAGE_RTYPE, id,
- &data);
- if (size == 0) {
- logger_printf("[mail] failed encoding message %ld: %d", id,
- bile_error(db->mail_bile));
- return 0;
- }
-
- bile_unmarshall_object(db->mail_bile, mail_object_fields,
- nitems(mail_object_fields), data, size, &msg, sizeof(msg), true);
- xfree(&data);
-
- if (msg.fidonet_msgid.id == 0) {
- msg.fidonet_msgid.id = id;
- msg.fidonet_msgid.zone = orig_node->zone;
- msg.fidonet_msgid.net = orig_node->net;
- msg.fidonet_msgid.node = orig_node->node;
- msg.fidonet_msgid.point = orig_node->point;
-
- if ((ret = mail_save(&msg)) != 0) {
- logger_printf("[mail] failed saving fidonet msgid for %ld: %d",
- id, ret);
- return 0;
- }
- }
-
- return fidopkt_encode(pkt_buf, db->config.fidonet_pkt_password,
- orig_node, &msg.fidonet_dest, &msg.fidonet_msgid,
- msg.time, db->config.timezone_utcoff, msg.fidonet_from,
- msg.fidonet_to, NULL, msg.fidonet_reply, msg.subject, msg.body);
-}
-
-bool
-mail_mark_fidonet_dispatched(unsigned long id)
-{
- struct mail_message msg;
- size_t size;
- char *data;
-
- size = bile_read_alloc(db->mail_bile, MAIL_SPOOL_MESSAGE_RTYPE, id,
- &data);
- if (size == 0)
- return false;
-
- bile_unmarshall_object(db->mail_bile, mail_object_fields,
- nitems(mail_object_fields), data, size, &msg, sizeof(msg), true);
- xfree(&data);
-
- msg.fidonet_need_dispatch = 0;
-
- if (mail_save(&msg) != 0)
- return false;
-
- return true;
}
--- mail.h Tue Mar 7 16:46:58 2023
+++ mail.h Wed Mar 8 17:02:37 2023
@@ -44,7 +44,6 @@ struct mail_message {
char fidonet_to[32];
char fidonet_msgid_orig[64];
char fidonet_reply[32];
- short fidonet_need_dispatch;
};
void mail_menu(struct session *s);