From 90524951fd45366c946d0a0b87358629ac959122 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 16 Sep 2005 05:42:49 +0000 Subject: [PATCH] *** empty log message *** --- citadel/imap_misc.c | 2 +- citadel/msgbase.c | 165 ++++++++++++++++++++++------------------ citadel/msgbase.h | 3 +- citadel/serv_calendar.c | 6 +- citadel/serv_chat.c | 2 +- citadel/serv_network.c | 16 ++-- citadel/serv_smtp.c | 10 +-- citadel/serv_vcard.c | 2 +- 8 files changed, 111 insertions(+), 95 deletions(-) diff --git a/citadel/imap_misc.c b/citadel/imap_misc.c index 192f9c833..00c652f27 100644 --- a/citadel/imap_misc.c +++ b/citadel/imap_misc.c @@ -398,7 +398,7 @@ void imap_append(int num_parms, char *parms[]) { else { /* Yes ... go ahead and post! */ if (msg != NULL) { - new_msgnum = CtdlSubmitMsg(msg, NULL, NULL, NULL, ""); + new_msgnum = CtdlSubmitMsg(msg, NULL, ""); } if (new_msgnum >= 0L) { cprintf("%s OK APPEND completed\r\n", parms[0]); diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 1f8fde2c9..3d0e42330 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -2034,13 +2034,13 @@ int ReplicationChecks(struct CtdlMessage *msg) { + + /* * Save a message to disk and submit it into the delivery system. */ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ - struct recptypes *recps_to, /* To: recipients (if mail) */ - struct recptypes *recps_cc, /* Cc: recipients (if mail) */ - struct recptypes *recps_bcc, /* Bcc: recipients (if mail) */ + struct recptypes *recps, /* recipients (if mail) */ char *force /* force a particular room? */ ) { char submit_filename[128]; @@ -2061,9 +2061,6 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ char *instr; struct ser_ret smr; char *hold_R, *hold_D; - int is_internet_mail = 0; - int force_to_sent = 0; /* Force to 'sent items' room */ - size_t tmp; lprintf(CTDL_DEBUG, "CtdlSubmitMsg() called\n"); if (is_valid_message(msg) == 0) return(-1); /* self check */ @@ -2133,16 +2130,13 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ } /* Goto the correct room */ - force_to_sent = 0; - if (recps_to) force_to_sent = 1; - if (recps_cc) force_to_sent = 1; - if (recps_bcc) force_to_sent = 1; + lprintf(CTDL_DEBUG, "Selected room %s\n", + (recps) ? CC->room.QRname : SENTITEMS); strcpy(hold_rm, CC->room.QRname); strcpy(actual_rm, CC->room.QRname); - if (force_to_sent) { + if (recps != NULL) { strcpy(actual_rm, SENTITEMS); } - lprintf(CTDL_DEBUG, "Selected room %s\n", actual_rm); /* If the user is a twit, move to the twit room for posting */ lprintf(CTDL_DEBUG, "Handling twit stuff: %s\n", @@ -2226,7 +2220,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ * message, we want to BYPASS saving the sender's copy (because there * is no local sender; it would otherwise go to the Trashcan). */ - if ((!CC->internal_pgm) || ((recps_to == NULL) && (recps_cc == NULL) && (recps_bcc == NULL))) { + if ((!CC->internal_pgm) || (recps == NULL)) { if (CtdlSaveMsgPointerInRoom(actual_rm, newmsgid, 0) != 0) { lprintf(CTDL_ERR, "ERROR saving message pointer!\n"); CtdlSaveMsgPointerInRoom(config.c_aideroom, @@ -2235,20 +2229,16 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ } /* For internet mail, drop a copy in the outbound queue room */ - is_internet_mail = 0; - if (recps_to != NULL) is_internet_mail = recps_to->num_internet; - if (recps_cc != NULL) is_internet_mail = recps_cc->num_internet; - if (recps_bcc != NULL) is_internet_mail = recps_bcc->num_internet; - if (is_internet_mail) { + if (recps != NULL) + if (recps->num_internet > 0) { CtdlSaveMsgPointerInRoom(SMTP_SPOOLOUT_ROOM, newmsgid, 0); } - /* If other rooms are specified in the To: field, drop them there too. */ - /******* FIXME FIXME ADD CC AND BCC HERE *********/ - if (recps_to != NULL) - if (recps_to->num_room > 0) - for (i=0; irecp_room, '|'); ++i) { - extract_token(recipient, recps_to->recp_room, i, + /* If other rooms are specified, drop them there too. */ + if (recps != NULL) + if (recps->num_room > 0) + for (i=0; irecp_room, '|'); ++i) { + extract_token(recipient, recps->recp_room, i, '|', sizeof recipient); lprintf(CTDL_DEBUG, "Delivering to room <%s>\n", recipient); CtdlSaveMsgPointerInRoom(recipient, newmsgid, 0); @@ -2263,11 +2253,10 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ /* If this is private, local mail, make a copy in the * recipient's mailbox and bump the reference count. */ - /******* FIXME FIXME ADD CC AND BCC HERE *********/ - if (recps_to != NULL) - if (recps_to->num_local > 0) - for (i=0; irecp_local, '|'); ++i) { - extract_token(recipient, recps_to->recp_local, i, + if (recps != NULL) + if (recps->num_local > 0) + for (i=0; irecp_local, '|'); ++i) { + extract_token(recipient, recps->recp_local, i, '|', sizeof recipient); lprintf(CTDL_DEBUG, "Delivering private local mail to <%s>\n", recipient); @@ -2296,11 +2285,10 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ * node. We'll revisit this again in a year or so when everyone has * a network spool receiver that can handle the new style messages. */ - /******* FIXME FIXME ADD CC AND BCC HERE *********/ - if (recps_to != NULL) - if (recps_to->num_ignet > 0) - for (i=0; irecp_ignet, '|'); ++i) { - extract_token(recipient, recps_to->recp_ignet, i, + if (recps != NULL) + if (recps->num_ignet > 0) + for (i=0; irecp_ignet, '|'); ++i) { + extract_token(recipient, recps->recp_ignet, i, '|', sizeof recipient); hold_R = msg->cm_fields['R']; @@ -2343,43 +2331,24 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ /* For internet mail, generate delivery instructions. * Yes, this is recursive. Deal with it. Infinite recursion does * not happen because the delivery instructions message does not - * have any recipients. + * contain a recipient. */ - if (is_internet_mail) { + if (recps != NULL) + if (recps->num_internet > 0) { lprintf(CTDL_DEBUG, "Generating delivery instructions\n"); - instr = malloc(SIZ * 4); - snprintf(instr, SIZ * 4, + instr = malloc(SIZ * 2); + snprintf(instr, SIZ * 2, "Content-type: %s\n\nmsgid|%ld\nsubmitted|%ld\n" "bounceto|%s@%s\n", SPOOLMIME, newmsgid, (long)time(NULL), msg->cm_fields['A'], msg->cm_fields['N'] ); - if (recps_to) if (strlen(recps_to->recp_internet) > 0) { - for (i=0; irecp_internet, '|'); ++i) { - tmp = strlen(instr); - extract_token(recipient, recps_to->recp_internet, i, '|', sizeof recipient); - snprintf(&instr[tmp], SIZ * 4 - tmp, - "remote|%s|0||\n", recipient); - } - } - - if (recps_cc) if (strlen(recps_cc->recp_internet) > 0) { - for (i=0; irecp_internet, '|'); ++i) { - tmp = strlen(instr); - extract_token(recipient, recps_cc->recp_internet, i, '|', sizeof recipient); - snprintf(&instr[tmp], SIZ * 4 - tmp, - "remote|%s|0||\n", recipient); - } - } - - if (recps_bcc) if (strlen(recps_bcc->recp_internet) > 0) { - for (i=0; irecp_internet, '|'); ++i) { - tmp = strlen(instr); - extract_token(recipient, recps_bcc->recp_internet, i, '|', sizeof recipient); - snprintf(&instr[tmp], SIZ * 4 - tmp, - "remote|%s|0||\n", recipient); - } + for (i=0; irecp_internet, '|'); ++i) { + size_t tmp = strlen(instr); + extract_token(recipient, recps->recp_internet, i, '|', sizeof recipient); + snprintf(&instr[tmp], SIZ * 2 - tmp, + "remote|%s|0||\n", recipient); } imsg = malloc(sizeof(struct CtdlMessage)); @@ -2389,7 +2358,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ imsg->cm_format_type = FMT_RFC822; imsg->cm_fields['A'] = strdup("Citadel"); imsg->cm_fields['M'] = instr; - CtdlSubmitMsg(imsg, NULL, NULL, NULL, SMTP_SPOOLOUT_ROOM); + CtdlSubmitMsg(imsg, NULL, SMTP_SPOOLOUT_ROOM); CtdlFreeMessage(imsg); } @@ -2398,6 +2367,11 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ + + + + + /* * Convenience function for generating small administrative messages. */ @@ -2424,7 +2398,7 @@ void quickie_message(char *from, char *to, char *room, char *text, } msg->cm_fields['M'] = strdup(text); - CtdlSubmitMsg(msg, recp, NULL, NULL, room); + CtdlSubmitMsg(msg, recp, room); CtdlFreeMessage(msg); if (recp != NULL) free(recp); } @@ -2659,10 +2633,11 @@ int CtdlCheckInternetMailPermission(struct ctdluser *who) { } - /* * Validate recipients, count delivery types and errors, and handle aliasing * FIXME check for dupes!!!!! + * Returns 0 if all addresses are ok, -1 if no addresses were specified, + * or the number of addresses found invalid. */ struct recptypes *validate_recipients(char *recipients) { struct recptypes *ret; @@ -2821,7 +2796,7 @@ struct recptypes *validate_recipients(char *recipients) { if ((ret->num_local + ret->num_internet + ret->num_ignet + ret->num_room + ret->num_error) == 0) { - ++ret->num_error; + ret->num_error = (-1); strcpy(ret->errormsg, "No recipients specified."); } @@ -2854,6 +2829,7 @@ void cmd_ent0(char *entargs) int anonymous = 0; char errmsg[SIZ]; int err = 0; + struct recptypes *valid = NULL; struct recptypes *valid_to = NULL; struct recptypes *valid_cc = NULL; struct recptypes *valid_bcc = NULL; @@ -2906,6 +2882,8 @@ void cmd_ent0(char *entargs) if (CC->user.axlevel < 2) { strcpy(recp, "sysop"); + strcpy(cc, ""); + strcpy(bcc, ""); } valid_to = validate_recipients(recp); @@ -2927,14 +2905,22 @@ void cmd_ent0(char *entargs) valid_bcc = validate_recipients(bcc); if (valid_bcc->num_error > 0) { - cprintf("%d %s\n", - ERROR + NO_SUCH_USER, valid_bcc->errormsg); + cprintf("%d %s\n", ERROR + NO_SUCH_USER, valid_bcc->errormsg); free(valid_to); free(valid_cc); free(valid_bcc); return; } + /* Recipient required, but none were specified */ + if ( (valid_to->num_error < 0) && (valid_cc->num_error < 0) && (valid_bcc->num_error < 0) ) { + free(valid_to); + free(valid_cc); + free(valid_bcc); + cprintf("%d %s\n", ERROR + NO_SUCH_USER, valid_to->errormsg); + return; + } + if (valid_to->num_internet + valid_cc->num_internet + valid_bcc->num_internet > 0) { if (CtdlCheckInternetMailPermission(&CC->user)==0) { cprintf("%d You do not have permission " @@ -2998,6 +2984,11 @@ void cmd_ent0(char *entargs) return; } + /* We don't need these anymore because we'll do it differently below */ + free(valid_to); + free(valid_cc); + free(valid_bcc); + /* Handle author masquerading */ if (CC->fake_postname[0]) { strcpy(masquerade_as, CC->fake_postname); @@ -3015,12 +3006,38 @@ void cmd_ent0(char *entargs) } else { cprintf("%d send message\n", SEND_LISTING); } + msg = CtdlMakeMessage(&CC->user, recp, CC->room.QRname, anonymous, format_type, masquerade_as, subject, NULL); + /* Put together one big recipients struct containing to/cc/bcc all in + * one. This is for the envelope. + */ + char *all_recps = malloc(SIZ * 3); + strcpy(all_recps, recp); + if (strlen(cc) > 0) { + if (strlen(all_recps) > 0) { + strcat(all_recps, ","); + } + strcat(all_recps, cc); + } + if (strlen(bcc) > 0) { + if (strlen(all_recps) > 0) { + strcat(all_recps, ","); + } + strcat(all_recps, bcc); + } + if (strlen(all_recps) > 0) { + valid = validate_recipients(all_recps); + } + else { + valid = NULL; + } + free(all_recps); + if (msg != NULL) { - msgnum = CtdlSubmitMsg(msg, valid_to, valid_cc, valid_bcc, ""); + msgnum = CtdlSubmitMsg(msg, valid, ""); if (do_confirm) { cprintf("%ld\n", msgnum); @@ -3041,9 +3058,9 @@ void cmd_ent0(char *entargs) CtdlFreeMessage(msg); } CC->fake_postname[0] = '\0'; - free(valid_to); - free(valid_cc); - free(valid_bcc); + if (valid != NULL) { + free(valid); + } return; } @@ -3498,7 +3515,7 @@ void CtdlWriteObject(char *req_room, /* Room to stuff it in */ ); } /* Now write the data */ - CtdlSubmitMsg(msg, NULL, NULL, NULL, roomname); + CtdlSubmitMsg(msg, NULL, roomname); CtdlFreeMessage(msg); } diff --git a/citadel/msgbase.h b/citadel/msgbase.h index d09cb6660..50d8b72f0 100644 --- a/citadel/msgbase.h +++ b/citadel/msgbase.h @@ -84,8 +84,7 @@ void cmd_msgp (char *cmdbuf); void cmd_opna (char *cmdbuf); long send_message (struct CtdlMessage *); void loadtroom (void); -long CtdlSubmitMsg(struct CtdlMessage *, struct recptypes *, - struct recptypes *, struct recptypes *, char *); +long CtdlSubmitMsg(struct CtdlMessage *, struct recptypes *, char *); void quickie_message (char *, char *, char *, char *, int, char *); void cmd_ent0 (char *entargs); void cmd_dele (char *delstr); diff --git a/citadel/serv_calendar.c b/citadel/serv_calendar.c index ec8be8344..fbc5ec510 100644 --- a/citadel/serv_calendar.c +++ b/citadel/serv_calendar.c @@ -323,7 +323,7 @@ void ical_send_a_reply(icalcomponent *request, char *action) { if (msg != NULL) { valid = validate_recipients(organizer_string); - CtdlSubmitMsg(msg, valid, NULL, NULL, ""); + CtdlSubmitMsg(msg, valid, ""); CtdlFreeMessage(msg); } } @@ -698,7 +698,7 @@ int ical_update_my_calendar_with_reply(icalcomponent *cal) { if (msg != NULL) { CIT_ICAL->avoid_sending_invitations = 1; - CtdlSubmitMsg(msg, NULL, NULL, NULL, roomname); + CtdlSubmitMsg(msg, NULL, roomname); CtdlFreeMessage(msg); CIT_ICAL->avoid_sending_invitations = 0; } @@ -1589,7 +1589,7 @@ void ical_send_out_invitations(icalcomponent *cal) { if (msg != NULL) { valid = validate_recipients(attendees_string); - CtdlSubmitMsg(msg, valid, NULL, NULL, ""); + CtdlSubmitMsg(msg, valid, ""); CtdlFreeMessage(msg); } } diff --git a/citadel/serv_chat.c b/citadel/serv_chat.c index 8b4e28c78..b323dab7a 100644 --- a/citadel/serv_chat.c +++ b/citadel/serv_chat.c @@ -634,7 +634,7 @@ int send_instant_message(char *lun, char *x_user, char *x_msg) * creating the room if necessary. */ create_room(PAGELOGROOM, 4, "", 0, 1, 0, VIEW_BBS); - msgnum = CtdlSubmitMsg(logmsg, NULL, NULL, NULL, PAGELOGROOM); + msgnum = CtdlSubmitMsg(logmsg, NULL, PAGELOGROOM); /* Now save a copy in the global log room, if configured */ if (strlen(config.c_logpages) > 0) { diff --git a/citadel/serv_network.c b/citadel/serv_network.c index 668ed2964..99b18724d 100644 --- a/citadel/serv_network.c +++ b/citadel/serv_network.c @@ -470,7 +470,7 @@ void network_spool_msg(long msgnum, void *userdata) { msg->cm_fields['R'] = strdup(nptr->name); valid = validate_recipients(nptr->name); - CtdlSubmitMsg(msg, valid, NULL, NULL, ""); + CtdlSubmitMsg(msg, valid, ""); free(valid); } @@ -573,7 +573,7 @@ void network_spool_msg(long msgnum, void *userdata) { msg->cm_fields['R'] = strdup(nptr->name); valid = validate_recipients(nptr->name); - CtdlSubmitMsg(msg, valid, NULL, NULL, ""); + CtdlSubmitMsg(msg, valid, ""); free(valid); } @@ -748,7 +748,7 @@ void network_deliver_digest(struct SpoolControl *sc) { fclose(sc->digestfp); sc->digestfp = NULL; - msgnum = CtdlSubmitMsg(msg, NULL, NULL, NULL, SMTP_SPOOLOUT_ROOM); + msgnum = CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM); CtdlFreeMessage(msg); /* Now generate the delivery instructions */ @@ -794,7 +794,7 @@ void network_deliver_digest(struct SpoolControl *sc) { imsg->cm_fields['M'] = instr; /* Save delivery instructions in spoolout room */ - CtdlSubmitMsg(imsg, NULL, NULL, NULL, SMTP_SPOOLOUT_ROOM); + CtdlSubmitMsg(imsg, NULL, SMTP_SPOOLOUT_ROOM); CtdlFreeMessage(imsg); } @@ -1220,7 +1220,7 @@ void network_bounce(struct CtdlMessage *msg, char *reason) { /* Now submit the message */ valid = validate_recipients(recipient); - if (valid != NULL) if (valid->num_error > 0) { + if (valid != NULL) if (valid->num_error != 0) { free(valid); valid = NULL; } @@ -1233,7 +1233,7 @@ void network_bounce(struct CtdlMessage *msg, char *reason) { if ( (valid == NULL) && (strlen(force_room) == 0) ) { strcpy(force_room, config.c_aideroom); } - CtdlSubmitMsg(msg, valid, NULL, NULL, force_room); + CtdlSubmitMsg(msg, valid, force_room); /* Clean up */ if (valid != NULL) free(valid); @@ -1380,7 +1380,7 @@ void network_process_buffer(char *buffer, long size) { /* Otherwise, does it have a recipient? If so, validate it... */ else if (msg->cm_fields['R'] != NULL) { recp = validate_recipients(msg->cm_fields['R']); - if (recp != NULL) if (recp->num_error > 0) { + if (recp != NULL) if (recp->num_error != 0) { network_bounce(msg, "A message you sent could not be delivered due to an invalid address.\n" "Please check the address and try sending the message again.\n"); @@ -1413,7 +1413,7 @@ void network_process_buffer(char *buffer, long size) { /* save the message into a room */ if (PerformNetprocHooks(msg, target_room) == 0) { msg->cm_flags = CM_SKIP_HOOKS; - CtdlSubmitMsg(msg, recp, NULL, NULL, target_room); + CtdlSubmitMsg(msg, recp, target_room); } CtdlFreeMessage(msg); free(recp); diff --git a/citadel/serv_smtp.c b/citadel/serv_smtp.c index c5da74dd3..313e27247 100644 --- a/citadel/serv_smtp.c +++ b/citadel/serv_smtp.c @@ -625,7 +625,7 @@ void smtp_rcpt(char *argbuf) { } valid = validate_recipients(recp); - if (valid->num_error > 0) { + if (valid->num_error != 0) { cprintf("599 5.1.1 Error: %s\r\n", valid->errormsg); free(valid); return; @@ -756,7 +756,7 @@ void smtp_data(void) { } else { /* Ok, we'll accept this message. */ - msgnum = CtdlSubmitMsg(msg, valid, NULL, NULL, ""); + msgnum = CtdlSubmitMsg(msg, valid, ""); if (msgnum > 0L) { sprintf(result, "250 2.0.0 Message accepted.\r\n"); } @@ -1309,14 +1309,14 @@ void smtp_do_bounce(char *instr) { valid = validate_recipients(bounceto); if (valid != NULL) { if (valid->num_error == 0) { - CtdlSubmitMsg(bmsg, valid, NULL, NULL, ""); + CtdlSubmitMsg(bmsg, valid, ""); successful_bounce = 1; } } /* If not, post it in the Aide> room */ if (successful_bounce == 0) { - CtdlSubmitMsg(bmsg, NULL, NULL, NULL, config.c_aideroom); + CtdlSubmitMsg(bmsg, NULL, config.c_aideroom); } /* Free up the memory we used */ @@ -1550,7 +1550,7 @@ void smtp_do_procmsg(long msgnum, void *userdata) { "attempted|%ld\n" "retry|%ld\n", SPOOLMIME, instr, (long)time(NULL), (long)retry ); - CtdlSubmitMsg(msg, NULL, NULL, NULL, SMTP_SPOOLOUT_ROOM); + CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM); CtdlFreeMessage(msg); } diff --git a/citadel/serv_vcard.c b/citadel/serv_vcard.c index fd197c16e..25b561d9c 100644 --- a/citadel/serv_vcard.c +++ b/citadel/serv_vcard.c @@ -811,7 +811,7 @@ void vcard_purge(struct ctdluser *usbuf) { msg->cm_fields['S'] = strdup("CANCEL"); - CtdlSubmitMsg(msg, NULL, NULL, NULL, ADDRESS_BOOK_ROOM); + CtdlSubmitMsg(msg, NULL, ADDRESS_BOOK_ROOM); CtdlFreeMessage(msg); } -- 2.39.2