AmendHub

Download:

jcs

/

subtext

/

amendments

/

394

mail: List newer messages first


jcs made amendment 394 about 1 year ago
--- mail.c Thu Mar 9 10:06:11 2023 +++ mail.c Fri Mar 10 21:43:08 2023 @@ -255,8 +255,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 = NULL, - *fidonet_to = NULL; + struct fidopkt_address fidonet_our_address, fidonet_to; struct fidopkt pkt = { 0 }; char *to_username = NULL, *tmp, *at; char c; @@ -307,7 +306,7 @@ mail_compose_start: } if ((at = strstr(to_username, "@")) != NULL) { - if (fidonet_our_address == 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"); session_flush(s); @@ -322,8 +321,7 @@ mail_compose_start: xfree(&to_username); continue; } - memcpy(&msg.fidonet_dest, fidonet_to, sizeof(msg.fidonet_dest)); - xfree(&fidonet_to); + 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) at[0] = '\0'; @@ -448,10 +446,10 @@ mail_compose_start: 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; + 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) { @@ -462,7 +460,7 @@ mail_compose_start: if (msg.fidonet_to[0]) { pkt.time = msg.time; - memcpy(&pkt.orig, fidonet_our_address, sizeof(pkt.orig)); + 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)); @@ -473,6 +471,7 @@ mail_compose_start: 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)) { session_printf(s, "failed!\r\n"); session_flush(s); @@ -499,9 +498,6 @@ mail_compose_done: if (to_username != NULL) xfree(&to_username); - if (fidonet_our_address != NULL) - xfree(&fidonet_our_address); - mail_free_message_strings(&msg); } @@ -565,6 +561,7 @@ mail_read(struct session *s, unsigned long id, short i { 'r', "Rr", "Reply to this message" }, { 'd', "Dd", "Delete this message" }, { 'u', "Uu", "Mark this message unread" }, + { 'm', "MmNn", "Compose new mail message" }, { 'l', "Ll", "Return and list mail messages" }, { 'q', "QqXx", "Return to message list" }, { '?', "?", "Show this help menu" }, @@ -689,6 +686,9 @@ mail_read(struct session *s, unsigned long id, short i ret = MAIL_READ_RETURN_DONE; done = true; break; + case 'm': + mail_compose(s, NULL, NULL, NULL, NULL); + break; case 'l': done = true; ret = MAIL_READ_RETURN_LIST; @@ -797,10 +797,10 @@ mail_find_ids_for_user(struct user *user, size_t *nret xfree(&all_mail_ids); if (ret_mail_ids != NULL) { - /* sort by message id for consistent ordering */ + /* sort by message id descending for consistent ordering */ for (i = 0; i < nmail_ids; i++) { for (j = 0; j < nmail_ids - i - 1; j++) { - if (mail_ids[j] > mail_ids[j + 1]) { + if (mail_ids[j] < mail_ids[j + 1]) { id = mail_ids[j]; mail_ids[j] = mail_ids[j + 1]; mail_ids[j + 1] = id; @@ -843,7 +843,7 @@ short mail_ingest_fidopkt(struct fidopkt *fidopkt) { struct user *to = NULL; - struct fidopkt_address *our_address = NULL; + struct fidopkt_address our_address; size_t n, nmail_ids, size; unsigned long *mail_ids = NULL; struct mail_message msg; @@ -863,14 +863,14 @@ mail_ingest_fidopkt(struct fidopkt *fidopkt) return -1; } - if (memcmp(&fidopkt->dest, our_address, + if (memcmp(&fidopkt->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, - our_address->zone, our_address->net, - our_address->node, our_address->point); + our_address.zone, our_address.net, + our_address.node, our_address.point); ret = 0; goto done; } @@ -911,10 +911,7 @@ mail_ingest_fidopkt(struct fidopkt *fidopkt) memset(&msg, 0, sizeof(msg)); msg.recipient_user_id = to->id; - if (fidopkt->time) - msg.time = fidopkt->time; - else - msg.time = Time; + msg.time = fidopkt->time; msg.subject = xstrdup(fidopkt->subject); msg.subject_size = strlen(msg.subject) + 1; msg.body = fidopkt->body; @@ -945,6 +942,5 @@ mail_ingest_fidopkt(struct fidopkt *fidopkt) done: if (to != NULL) xfree(&to); - xfree(&our_address); return ret; }