AmendHub

Download:

jcs

/

subtext

/

amendments

/

404

mail: Adapt to fidopkt changes


jcs made amendment 404 about 1 year ago
--- mail.c Fri Mar 10 21:43:08 2023 +++ mail.c Mon Mar 13 22:27:46 2023 @@ -256,7 +256,7 @@ mail_compose(struct session *s, char *initial_to, char struct user *to_user = NULL; struct mail_message msg = { 0 }; struct fidopkt_address fidonet_our_address, fidonet_to; - struct fidopkt pkt = { 0 }; + struct fidopkt_message fidomsg = { 0 }; char *to_username = NULL, *tmp, *at; char c; @@ -316,7 +316,8 @@ mail_compose_start: 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); + "%s destination \"%s\" (^C to cancel)\r\n", + db->config.fidonet_network, at + 1); session_flush(s); xfree(&to_username); continue; @@ -327,7 +328,7 @@ mail_compose_start: at[0] = '\0'; strlcpy(msg.fidonet_from, s->user->username, sizeof(msg.fidonet_from)); - session_printf(s, " (FidoNet)\r\n"); + session_printf(s, " (%s)\r\n", db->config.fidonet_network); session_flush(s); } else { session_output(s, "\r\n", 2); @@ -404,9 +405,11 @@ 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_to[0] ? "FidoNet " : ""); + session_printf(s, "\r\n{{B}}(S){{/B}}end "); + if (msg.fidonet_to[0]) + session_printf(s, "%s ", db->config.fidonet_network); + session_printf(s, "message, " + "{{B}}(E){{/B}}dit again, or {{B}}(C){{/B}}ancel? "); session_flush(s); c = session_input_char(s); @@ -429,23 +432,23 @@ mail_compose_start: case '\r': /* send */ if (msg.fidonet_to[0]) - session_printf(s, "Queueing mail for FidoNet delivery..."); + session_printf(s, "Queueing mail for %s delivery...", + db->config.fidonet_network); else session_printf(s, "Sending mail..."); session_flush(s); msg.time = Time; msg.sender_user_id = s->user->id; + msg.id = bile_next_id(db->mail_bile, MAIL_SPOOL_MESSAGE_RTYPE); - 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.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; @@ -459,20 +462,24 @@ mail_compose_start: } 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; + 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(pkt.reply, fidonet_reply_msgid, - sizeof(pkt.reply)); - pkt.msgid = msg.fidonet_msgid; - pkt.attr = FIDOPKT_MSG_ATTR_PRIVATE; - if (!binkp_store_outbound_fidopkt(&pkt)) { + 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)) { session_printf(s, "failed!\r\n"); session_flush(s); break; @@ -840,7 +847,7 @@ done: } short -mail_ingest_fidopkt(struct fidopkt *fidopkt) +mail_ingest_fidopkt_message(struct fidopkt_message *fidomsg) { struct user *to = NULL; struct fidopkt_address our_address; @@ -863,22 +870,23 @@ mail_ingest_fidopkt(struct fidopkt *fidopkt) return -1; } - if (memcmp(&fidopkt->dest, &our_address, + if (memcmp(&fidomsg->header.dest, &our_address, sizeof(struct fidopkt_address)) != 0) { - logger_printf("[mail] message is destined for %d:%d/%d.%d, not " - "us (%d:%d/%d.%d)", - fidopkt->dest.zone, fidopkt->dest.net, - fidopkt->dest.node, fidopkt->dest.point, + 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, our_address.zone, our_address.net, our_address.node, our_address.point); ret = 0; goto done; } - to = user_find_by_username(fidopkt->to); + to = user_find_by_username(fidomsg->to); if (to == NULL) { + /* TODO: Should these go to sysop? Or mail to "sysop"? */ logger_printf("[mail] no local user \"%s\", discarding message", - fidopkt->to); + fidomsg->to); ret = 0; goto done; } @@ -893,10 +901,10 @@ mail_ingest_fidopkt(struct fidopkt *fidopkt) nitems(mail_object_fields), data, size, &msg, sizeof(msg), false); xfree(&data); - if (memcmp(&msg.fidonet_msgid, &fidopkt->msgid, + if (memcmp(&msg.fidonet_msgid, &fidomsg->msgid, sizeof(struct fidopkt_msgid)) == 0) { logger_printf("[mail] already have fidonet msg %s (%ld), " - "skipping", fidopkt->msgid_orig, msg.id); + "skipping", fidomsg->msgid_orig, msg.id); ret = 0; break; } @@ -911,33 +919,34 @@ mail_ingest_fidopkt(struct fidopkt *fidopkt) memset(&msg, 0, sizeof(msg)); msg.recipient_user_id = to->id; - msg.time = fidopkt->time; - msg.subject = xstrdup(fidopkt->subject); - msg.subject_size = strlen(msg.subject) + 1; - msg.body = fidopkt->body; - msg.body_size = fidopkt->body_len + 1; + 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.fidonet_msgid = fidopkt->msgid; - msg.fidonet_orig = fidopkt->orig; - msg.fidonet_dest = fidopkt->dest; + msg.fidonet_msgid = fidomsg->msgid; + msg.fidonet_orig = fidomsg->header.orig; + msg.fidonet_dest = fidomsg->header.dest; - strlcpy(msg.fidonet_from, fidopkt->from, sizeof(msg.fidonet_from)); - strlcpy(msg.fidonet_msgid_orig, fidopkt->msgid_orig, + 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, fidopkt->reply, sizeof(msg.fidonet_reply)); + strlcpy(msg.fidonet_reply, fidomsg->reply, sizeof(msg.fidonet_reply)); if (mail_save(&msg) != 0) { - logger_printf("[binkp] failed saving mail from %d:%d/%d.%d to " + logger_printf("[binkp] failed saving mail from %u:%u/%u.%u to " "local user %s", - fidopkt->orig.zone, fidopkt->orig.net, fidopkt->orig.node, - fidopkt->orig.point, to->username); + fidomsg->header.orig.zone, fidomsg->header.orig.net, + fidomsg->header.orig.node, fidomsg->header.orig.point, + to->username); ret = -1; goto done; } - logger_printf("[binkp] imported mail from %d:%d/%d.%d to local user %s", - fidopkt->orig.zone, fidopkt->orig.net, fidopkt->orig.node, - fidopkt->orig.point, to->username); + 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); done: if (to != NULL) --- mail.h Wed Mar 8 17:02:37 2023 +++ mail.h Mon Mar 13 12:06:41 2023 @@ -52,10 +52,8 @@ void mail_compose(struct session *s, char *to, char *s 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(struct fidopkt *fidopkt); -size_t mail_ids_needing_fidonet_dispatch(unsigned long **ids); +short mail_ingest_fidopkt_message(struct fidopkt_message *fidomsg); size_t mail_encode_as_fidopkt(unsigned long id, struct fidopkt_address *orig_node, char **pkt_buf); -bool mail_mark_fidonet_dispatched(unsigned long id); #endif