AmendHub

Download:

jcs

/

subtext

/

amendments

/

411

mail: Use FTN terminology


jcs made amendment 411 about 1 year ago
--- mail.c Mon Mar 13 22:27:46 2023 +++ mail.c Tue Mar 14 08:47:07 2023 @@ -57,20 +57,20 @@ static const struct bile_object_field mail_object_fiel { offsetof(struct mail_message, parent_message_id), member_size(struct mail_message, parent_message_id), -1 }, - { offsetof(struct mail_message, fidonet_msgid), - member_size(struct mail_message, fidonet_msgid), -1 }, - { offsetof(struct mail_message, fidonet_orig), - member_size(struct mail_message, fidonet_orig), -1 }, - { offsetof(struct mail_message, fidonet_dest), - member_size(struct mail_message, fidonet_dest), -1 }, - { offsetof(struct mail_message, fidonet_from), - member_size(struct mail_message, fidonet_from), -1 }, - { offsetof(struct mail_message, fidonet_to), - member_size(struct mail_message, fidonet_to), -1 }, - { offsetof(struct mail_message, fidonet_msgid_orig), - 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, ftn_msgid), + member_size(struct mail_message, ftn_msgid), -1 }, + { offsetof(struct mail_message, ftn_orig), + member_size(struct mail_message, ftn_orig), -1 }, + { offsetof(struct mail_message, ftn_dest), + member_size(struct mail_message, ftn_dest), -1 }, + { offsetof(struct mail_message, ftn_from), + member_size(struct mail_message, ftn_from), -1 }, + { offsetof(struct mail_message, ftn_to), + member_size(struct mail_message, ftn_to), -1 }, + { offsetof(struct mail_message, ftn_msgid_orig), + member_size(struct mail_message, ftn_msgid_orig), -1 }, + { offsetof(struct mail_message, ftn_reply), + member_size(struct mail_message, ftn_reply), -1 }, }; static const size_t nmail_object_fields = nitems(mail_object_fields); @@ -251,12 +251,12 @@ handle_opt: void mail_compose(struct session *s, char *initial_to, char *initial_subject, - char *initial_body, char *fidonet_reply_msgid) + char *initial_body, char *ftn_reply_msgid) { struct user *to_user = NULL; struct mail_message msg = { 0 }; - struct fidopkt_address fidonet_our_address, fidonet_to; - struct fidopkt_message fidomsg = { 0 }; + struct fidopkt_address ftn_our_address, ftn_to; + struct fidopkt_message ftnmsg = { 0 }; char *to_username = NULL, *tmp, *at; char c; @@ -267,8 +267,7 @@ mail_compose(struct session *s, char *initial_to, char return; } - fidopkt_parse_address(db->config.fidonet_node_addr, - &fidonet_our_address); + fidopkt_parse_address(db->config.ftn_node_addr, &ftn_our_address); if (initial_to) { to_username = xstrdup(initial_to); @@ -286,7 +285,7 @@ mail_compose(struct session *s, char *initial_to, char goto mail_compose_done; } - session_printf(s, "{{B}}Compose New Private Mail{{/B}}\r\n"); + session_printf(s, "{{B}}Compose New Mail{{/B}}\r\n"); session_printf(s, "{{B}}From: {{/B}} %s\r\n", s->user->username); session_flush(s); @@ -306,29 +305,29 @@ mail_compose_start: } if ((at = strstr(to_username, "@")) != NULL) { - if (fidonet_our_address.zone == 0) { - session_printf(s, "\r\n{{B}}Error:{{/B}}{{#}} FidoNet " - "mail is not supported at this time.\r\n"); + if (ftn_our_address.zone == 0) { + session_printf(s, "\r\n{{B}}Error:{{/B}}{{#}} NetMail " + "is not supported at this time.\r\n"); session_flush(s); xfree(&to_username); continue; } - if (!fidopkt_parse_address(at + 1, &fidonet_to)) { + if (!fidopkt_parse_address(at + 1, &ftn_to)) { session_printf(s, "\r\n{{B}}Error:{{/B}}{{#}} Invalid " "%s destination \"%s\" (^C to cancel)\r\n", - db->config.fidonet_network, at + 1); + db->config.ftn_network, at + 1); session_flush(s); xfree(&to_username); continue; } - memcpy(&msg.fidonet_dest, &fidonet_to, sizeof(msg.fidonet_dest)); - strlcpy(msg.fidonet_to, to_username, sizeof(msg.fidonet_to)); - if ((at = strstr(msg.fidonet_to, "@")) != NULL) + memcpy(&msg.ftn_dest, &ftn_to, sizeof(msg.ftn_dest)); + strlcpy(msg.ftn_to, to_username, sizeof(msg.ftn_to)); + if ((at = strstr(msg.ftn_to, "@")) != NULL) at[0] = '\0'; - strlcpy(msg.fidonet_from, s->user->username, - sizeof(msg.fidonet_from)); - session_printf(s, " (%s)\r\n", db->config.fidonet_network); + strlcpy(msg.ftn_from, s->user->username, + sizeof(msg.ftn_from)); + session_printf(s, " (%s)\r\n", db->config.ftn_network); session_flush(s); } else { session_output(s, "\r\n", 2); @@ -406,8 +405,8 @@ mail_compose_start: for (;;) { session_printf(s, "\r\n{{B}}(S){{/B}}end "); - if (msg.fidonet_to[0]) - session_printf(s, "%s ", db->config.fidonet_network); + if (msg.ftn_to[0]) + session_printf(s, "%s ", db->config.ftn_network); session_printf(s, "message, " "{{B}}(E){{/B}}dit again, or {{B}}(C){{/B}}ancel? "); session_flush(s); @@ -431,9 +430,9 @@ mail_compose_start: case '\n': case '\r': /* send */ - if (msg.fidonet_to[0]) - session_printf(s, "Queueing mail for %s delivery...", - db->config.fidonet_network); + if (msg.ftn_to[0]) + session_printf(s, "Queueing %s NetMail for delivery...", + db->config.ftn_network); else session_printf(s, "Sending mail..."); session_flush(s); @@ -442,17 +441,17 @@ mail_compose_start: msg.sender_user_id = s->user->id; 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)); + if (msg.ftn_to[0]) { + if (ftn_reply_msgid != NULL && ftn_reply_msgid[0]) + strlcpy(msg.ftn_reply, ftn_reply_msgid, + sizeof(ftn_reply_msgid)); - msg.fidonet_msgid.id = 0x10FF0000 | - ((unsigned long)fidonet_our_address.node << 24) | 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; + msg.ftn_msgid.id = 0x10FF0000 | + ((unsigned long)ftn_our_address.node << 24) | msg.id; + msg.ftn_msgid.zone = ftn_our_address.zone; + msg.ftn_msgid.net = ftn_our_address.net; + msg.ftn_msgid.node = ftn_our_address.node; + msg.ftn_msgid.point = ftn_our_address.point; } if (mail_save(&msg) != 0) { @@ -461,25 +460,24 @@ mail_compose_start: break; } - if (msg.fidonet_to[0]) { - fidomsg.time = msg.time; - memcpy(&fidomsg.header.orig, &fidonet_our_address, - sizeof(fidomsg.header.orig)); - memcpy(&fidomsg.header.dest, &msg.fidonet_dest, - sizeof(fidomsg.header.dest)); - strlcpy(fidomsg.to, msg.fidonet_to, sizeof(fidomsg.to)); - strlcpy(fidomsg.from, msg.fidonet_from, - sizeof(fidomsg.from)); - strlcpy(fidomsg.subject, msg.subject, - sizeof(fidomsg.subject)); - fidomsg.body = msg.body; - fidomsg.body_len = msg.body_size; - if (fidonet_reply_msgid != NULL && fidonet_reply_msgid[0]) - strlcpy(fidomsg.reply, fidonet_reply_msgid, - sizeof(fidomsg.reply)); - fidomsg.msgid = msg.fidonet_msgid; - fidomsg.attr = FIDOPKT_MSG_ATTR_PRIVATE; - if (!binkp_store_outbound_message(&fidomsg)) { + if (msg.ftn_to[0]) { + ftnmsg.time = msg.time; + memcpy(&ftnmsg.header.orig, &ftn_our_address, + sizeof(ftnmsg.header.orig)); + memcpy(&ftnmsg.header.dest, &msg.ftn_dest, + sizeof(ftnmsg.header.dest)); + strlcpy(ftnmsg.to, msg.ftn_to, sizeof(ftnmsg.to)); + strlcpy(ftnmsg.from, msg.ftn_from, sizeof(ftnmsg.from)); + strlcpy(ftnmsg.subject, msg.subject, + sizeof(ftnmsg.subject)); + ftnmsg.body = msg.body; + ftnmsg.body_len = msg.body_size; + if (ftn_reply_msgid != NULL && ftn_reply_msgid[0]) + strlcpy(ftnmsg.reply, ftn_reply_msgid, + sizeof(ftnmsg.reply)); + ftnmsg.msgid = msg.ftn_msgid; + ftnmsg.attr = FIDOPKT_MSG_ATTR_PRIVATE; + if (!binkp_scan_message(&ftnmsg)) { session_printf(s, "failed!\r\n"); session_flush(s); break; @@ -518,7 +516,7 @@ mail_list(struct session *s, size_t nmail_ids, unsigne struct username_cache *user; char *data; - session_printf(s, "{{B}}Private Mail (Page %ld of %ld){{/B}}\r\n", + session_printf(s, "{{B}}Mail (Page %ld of %ld){{/B}}\r\n", page, pages); session_printf(s, "%s# Flg Date From Subject%s\r\n", ansi(s, ANSI_BOLD, ANSI_END), ansi(s, ANSI_RESET, ANSI_END)); @@ -533,11 +531,11 @@ mail_list(struct session *s, size_t nmail_ids, unsigne nitems(mail_object_fields), data, size, &msg, sizeof(msg), true); xfree(&data); - if (msg.fidonet_from[0] && msg.recipient_user_id) { - snprintf(from, sizeof(from), "%s@%d:%d/%d.%d", - msg.fidonet_from, msg.fidonet_msgid.zone, - msg.fidonet_msgid.net, msg.fidonet_msgid.node, - msg.fidonet_msgid.point); + if (msg.ftn_from[0] && msg.recipient_user_id) { + snprintf(from, sizeof(from), "%s@%u:%u/%u.%u", + msg.ftn_from, msg.ftn_msgid.zone, + msg.ftn_msgid.net, msg.ftn_msgid.node, + msg.ftn_msgid.point); } else { user = user_username(msg.sender_user_id); strlcpy(from, user ? user->username : "(unknown)", @@ -597,13 +595,13 @@ mail_read(struct session *s, unsigned long id, short i nitems(mail_object_fields), data, size, &msg, sizeof(msg), true); xfree(&data); - if (msg.fidonet_from[0]) { - size = snprintf(from, sizeof(from), "%s@%d:%d/%d", - msg.fidonet_from, msg.fidonet_msgid.zone, - msg.fidonet_msgid.net, msg.fidonet_msgid.node); - if (msg.fidonet_msgid.point) - snprintf(from + size, sizeof(from) - size, ".%d", - msg.fidonet_msgid.point); + if (msg.ftn_from[0]) { + size = snprintf(from, sizeof(from), "%s@%u:%u/%u", + msg.ftn_from, msg.ftn_msgid.zone, msg.ftn_msgid.net, + msg.ftn_msgid.node); + if (msg.ftn_msgid.point) + snprintf(from + size, sizeof(from) - size, ".%u", + msg.ftn_msgid.point); } else { user = user_username(msg.sender_user_id); if (user) @@ -612,13 +610,13 @@ mail_read(struct session *s, unsigned long id, short i strlcpy(from, "(Unknown)", sizeof(from)); } - if (msg.fidonet_to[0]) { - snprintf(to, sizeof(to), "%s@%d:%d/%d", - msg.fidonet_to, msg.fidonet_dest.zone, - msg.fidonet_dest.net, msg.fidonet_dest.node); - if (msg.fidonet_dest.point) - snprintf(to + size, sizeof(to) - size, ".%d", - msg.fidonet_dest.point); + if (msg.ftn_to[0]) { + snprintf(to, sizeof(to), "%s@%u:%u/%u", + msg.ftn_to, msg.ftn_dest.zone, msg.ftn_dest.net, + msg.ftn_dest.node); + if (msg.ftn_dest.point) + snprintf(to + size, sizeof(to) - size, ".%u", + msg.ftn_dest.point); } else { user = user_username(msg.recipient_user_id); if (user) @@ -648,7 +646,7 @@ mail_read(struct session *s, unsigned long id, short i } snprintf(prompt, sizeof(prompt), "Mail:Message %d", idx); - snprintf(title, sizeof(title), "Private Mail: Message %d", idx); + snprintf(title, sizeof(title), "Mail: Message %d", idx); while (!done && !s->ending) { c = session_menu(s, title, prompt, opts, nitems(opts), @@ -667,7 +665,7 @@ mail_read(struct session *s, unsigned long id, short i sprintf(reply_subject, "Re: %s", msg.subject); mail_compose(s, from, reply_subject, NULL, - msg.fidonet_msgid_orig[0] ? msg.fidonet_msgid_orig : NULL); + msg.ftn_msgid_orig[0] ? msg.ftn_msgid_orig : NULL); xfree(&reply_subject); break; case 'd': @@ -847,7 +845,7 @@ done: } short -mail_ingest_fidopkt_message(struct fidopkt_message *fidomsg) +mail_toss_ftn_message(struct fidopkt_message *ftnmsg) { struct user *to = NULL; struct fidopkt_address our_address; @@ -857,36 +855,38 @@ mail_ingest_fidopkt_message(struct fidopkt_message *fi short ret = 1; char *data; - if (db->config.fidonet_node_addr[0] == 0) { - logger_printf("[mail] local FidoNet node address must be " + if (db->config.ftn_node_addr[0] == 0) { + logger_printf("[mail] local FTN node address must be " "configured in settings"); return -1; } - if (!fidopkt_parse_address(db->config.fidonet_node_addr, + if (!fidopkt_parse_address(db->config.ftn_node_addr, &our_address)) { - logger_printf("[mail] failed parsing local FidoNet node address " - "\"%s\", fix in settings", db->config.fidonet_node_addr); + logger_printf("[mail] failed parsing local FTN node address " + "\"%s\", fix in settings", db->config.ftn_node_addr); return -1; } - if (memcmp(&fidomsg->header.dest, &our_address, + if (memcmp(&ftnmsg->header.dest, &our_address, sizeof(struct fidopkt_address)) != 0) { - logger_printf("[mail] message is destined for %u:%u/%u.%u, not " - "us (%u:%u/%u.%u)", - fidomsg->header.dest.zone, fidomsg->header.dest.net, - fidomsg->header.dest.node, fidomsg->header.dest.point, + logger_printf("[mail] NetMail message is destined for " + "%u:%u/%u.%u, not us (%u:%u/%u.%u)", + ftnmsg->header.dest.zone, ftnmsg->header.dest.net, + ftnmsg->header.dest.node, ftnmsg->header.dest.point, our_address.zone, our_address.net, our_address.node, our_address.point); ret = 0; goto done; } - to = user_find_by_username(fidomsg->to); + to = user_find_by_username(ftnmsg->to); + if (to == NULL && strcasecmp(ftnmsg->to, "sysop") == 0) + to = user_find_by_username(user_first_sysop_username()); if (to == NULL) { - /* TODO: Should these go to sysop? Or mail to "sysop"? */ + /* TODO: Should these go to sysop? */ logger_printf("[mail] no local user \"%s\", discarding message", - fidomsg->to); + ftnmsg->to); ret = 0; goto done; } @@ -901,10 +901,11 @@ mail_ingest_fidopkt_message(struct fidopkt_message *fi nitems(mail_object_fields), data, size, &msg, sizeof(msg), false); xfree(&data); - if (memcmp(&msg.fidonet_msgid, &fidomsg->msgid, + if (memcmp(&msg.ftn_msgid, &ftnmsg->msgid, sizeof(struct fidopkt_msgid)) == 0) { - logger_printf("[mail] already have fidonet msg %s (%ld), " - "skipping", fidomsg->msgid_orig, msg.id); + logger_printf("[mail] already have %s NetMail message %s " + "(%ld), skipping", db->config.ftn_network, + ftnmsg->msgid_orig, msg.id); ret = 0; break; } @@ -919,34 +920,35 @@ mail_ingest_fidopkt_message(struct fidopkt_message *fi memset(&msg, 0, sizeof(msg)); msg.recipient_user_id = to->id; - msg.time = fidomsg->time; - msg.subject = xstrdup(fidomsg->subject); - msg.subject_size = strlen(fidomsg->subject) + 1; - msg.body = fidomsg->body; - msg.body_size = fidomsg->body_len + 1; + msg.time = ftnmsg->time; + msg.subject = xstrdup(ftnmsg->subject); + msg.subject_size = strlen(ftnmsg->subject) + 1; + msg.body = ftnmsg->body; + msg.body_size = ftnmsg->body_len + 1; - msg.fidonet_msgid = fidomsg->msgid; - msg.fidonet_orig = fidomsg->header.orig; - msg.fidonet_dest = fidomsg->header.dest; + msg.ftn_msgid = ftnmsg->msgid; + msg.ftn_orig = ftnmsg->header.orig; + msg.ftn_dest = ftnmsg->header.dest; - strlcpy(msg.fidonet_from, fidomsg->from, sizeof(msg.fidonet_from)); - strlcpy(msg.fidonet_msgid_orig, fidomsg->msgid_orig, - sizeof(msg.fidonet_msgid_orig)); - strlcpy(msg.fidonet_reply, fidomsg->reply, sizeof(msg.fidonet_reply)); + strlcpy(msg.ftn_from, ftnmsg->from, sizeof(msg.ftn_from)); + strlcpy(msg.ftn_msgid_orig, ftnmsg->msgid_orig, + sizeof(msg.ftn_msgid_orig)); + strlcpy(msg.ftn_reply, ftnmsg->reply, sizeof(msg.ftn_reply)); if (mail_save(&msg) != 0) { - logger_printf("[binkp] failed saving mail from %u:%u/%u.%u to " - "local user %s", - fidomsg->header.orig.zone, fidomsg->header.orig.net, - fidomsg->header.orig.node, fidomsg->header.orig.point, + logger_printf("[binkp] failed saving %s NetMail message from " + "%u:%u/%u.%u to local user %s", db->config.ftn_network, + ftnmsg->header.orig.zone, ftnmsg->header.orig.net, + ftnmsg->header.orig.node, ftnmsg->header.orig.point, to->username); ret = -1; goto done; } - logger_printf("[binkp] imported mail from %u:%u/%u.%u to local user %s", - fidomsg->header.orig.zone, fidomsg->header.orig.net, - fidomsg->header.orig.node, fidomsg->header.orig.point, to->username); + logger_printf("[binkp] tossed %s NetMail from %u:%u/%u.%u to local " + "user %s", db->config.ftn_network, + ftnmsg->header.orig.zone, ftnmsg->header.orig.net, + ftnmsg->header.orig.node, ftnmsg->header.orig.point, to->username); done: if (to != NULL) --- mail.h Mon Mar 13 12:06:41 2023 +++ mail.h Tue Mar 14 10:16:31 2023 @@ -37,22 +37,22 @@ struct mail_message { char *body; unsigned long parent_message_id; - struct fidopkt_msgid fidonet_msgid; - struct fidopkt_address fidonet_orig; - struct fidopkt_address fidonet_dest; - char fidonet_from[32]; - char fidonet_to[32]; - char fidonet_msgid_orig[64]; - char fidonet_reply[32]; + struct fidopkt_msgid ftn_msgid; + struct fidopkt_address ftn_orig; + struct fidopkt_address ftn_dest; + char ftn_from[32]; + char ftn_to[32]; + char ftn_msgid_orig[64]; + char ftn_reply[32]; }; void mail_menu(struct session *s); void mail_compose(struct session *s, char *to, char *subject, char *body, - char *fidonet_reply_msgid); + char *ftn_reply_msgid); short mail_save(struct mail_message *msg); size_t mail_find_ids_for_user(struct user *user, size_t *nmail_ids, unsigned long **mail_ids, size_t offset, size_t limit, bool only_unread); -short mail_ingest_fidopkt_message(struct fidopkt_message *fidomsg); +short mail_toss_ftn_message(struct fidopkt_message *fidomsg); size_t mail_encode_as_fidopkt(unsigned long id, struct fidopkt_address *orig_node, char **pkt_buf);