X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmsgbase.c;h=824b51bd337974b232da9bd2644ccaed22db1085;hb=6e2775961a4c77515aec8718b18f375497678696;hp=1bff449e2f9002fbaf70bd690fe757eeec98b2bb;hpb=88883a6bf9e4859707fb43c3cd3608fb5166f76c;p=citadel.git diff --git a/citadel/msgbase.c b/citadel/msgbase.c index 1bff449e2..824b51bd3 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -1084,26 +1084,37 @@ void mime_download(char *name, char *filename, char *partnum, char *disp, char *encoding, char *cbid, void *cbuserdata) { int rv = 0; + CitContext *CCC = MyContext(); /* Silently go away if there's already a download open. */ - if (CC->download_fp != NULL) + if (CCC->download_fp != NULL) return; if ( - (!IsEmptyStr(partnum) && (!strcasecmp(CC->download_desired_section, partnum))) - || (!IsEmptyStr(cbid) && (!strcasecmp(CC->download_desired_section, cbid))) + (!IsEmptyStr(partnum) && (!strcasecmp(CCC->download_desired_section, partnum))) + || (!IsEmptyStr(cbid) && (!strcasecmp(CCC->download_desired_section, cbid))) ) { - CC->download_fp = tmpfile(); - if (CC->download_fp == NULL) + CCC->download_fp = tmpfile(); + if (CCC->download_fp == NULL) { + syslog(LOG_EMERG, "mime_download(): Couldn't write: %s\n", + strerror(errno)); + cprintf("%d cannot open temporary file: %s\n", + ERROR + INTERNAL_ERROR, strerror(errno)); return; + } rv = fwrite(content, length, 1, CC->download_fp); - if (rv == -1) { + if (rv <= 0) { syslog(LOG_EMERG, "mime_download(): Couldn't write: %s\n", strerror(errno)); + cprintf("%d unable to write tempfile.\n", + ERROR + TOO_BIG); + fclose(CCC->download_fp); + CCC->download_fp = NULL; + return; } - fflush(CC->download_fp); - rewind(CC->download_fp); + fflush(CCC->download_fp); + rewind(CCC->download_fp); OpenCmdResult(filename, cbtype); } @@ -1239,26 +1250,28 @@ int is_valid_message(struct CtdlMessage *msg) { return 1; } +void CtdlFreeMessageContents(struct CtdlMessage *msg) +{ + int i; + for (i = 0; i < 256; ++i) + if (msg->cm_fields[i] != NULL) { + free(msg->cm_fields[i]); + } + + msg->cm_magic = 0; /* just in case */ +} /* * 'Destructor' for struct CtdlMessage */ void CtdlFreeMessage(struct CtdlMessage *msg) { - int i; - if (is_valid_message(msg) == 0) { if (msg != NULL) free (msg); return; } - - for (i = 0; i < 256; ++i) - if (msg->cm_fields[i] != NULL) { - free(msg->cm_fields[i]); - } - - msg->cm_magic = 0; /* just in case */ + CtdlFreeMessageContents(msg); free(msg); } @@ -1354,7 +1367,7 @@ void fixed_output(char *name, char *filename, char *partnum, char *disp, ptr = html_to_ascii(content, length, 80, 0); wlen = strlen(ptr); client_write(ptr, wlen); - if (ptr[wlen-1] != '\n') { + if ((wlen > 0) && (ptr[wlen-1] != '\n')) { cprintf("\n"); } free(ptr); @@ -3254,21 +3267,25 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ imsg->cm_fields['A'] = strdup("Citadel"); imsg->cm_fields['J'] = strdup("do not journal"); imsg->cm_fields['M'] = instr; /* imsg owns this memory now */ - imsg->cm_fields['W'] = strdup(recipient); + imsg->cm_fields['2'] = strdup(recipient); CtdlSubmitMsg(imsg, NULL, FNBL_QUEUE_ROOM, 0); CtdlFreeMessage(imsg); } } else { syslog(LOG_DEBUG, "No user <%s>\n", recipient); - CtdlSaveMsgPointerInRoom(config.c_aideroom, - newmsgid, 0, msg); + CtdlSaveMsgPointerInRoom(config.c_aideroom, newmsgid, 0, msg); } } /* Perform "after save" hooks */ syslog(LOG_DEBUG, "Performing after-save hooks\n"); + if (msg->cm_fields['3'] != NULL) free(msg->cm_fields['3']); + msg->cm_fields['3'] = malloc(20); + snprintf(msg->cm_fields['3'], 20, "%ld", newmsgid); PerformMessageHooks(msg, EVT_AFTERSAVE); + free(msg->cm_fields['3']); + msg->cm_fields['3'] = NULL; /* For IGnet mail, we have to save a new copy into the spooler for * each recipient, with the R and D fields set to the recipient and @@ -4255,6 +4272,7 @@ void free_recipients(struct recptypes *valid) { */ void cmd_ent0(char *entargs) { + struct CitContext *CCC = CC; int post = 0; char recp[SIZ]; char cc[SIZ]; @@ -4275,6 +4293,7 @@ void cmd_ent0(char *entargs) char subject[SIZ]; int subject_required = 0; int do_confirm = 0; + int verbose_reply = 0; long msgnum; int i, j; char buf[256]; @@ -4293,6 +4312,7 @@ void cmd_ent0(char *entargs) do_confirm = extract_int(entargs, 6); extract_token(cc, entargs, 7, '|', sizeof cc); extract_token(bcc, entargs, 8, '|', sizeof bcc); + verbose_reply = extract_int(entargs, 9); switch(CC->room.QRdefaultview) { case VIEW_NOTES: case VIEW_WIKI: @@ -4326,11 +4346,11 @@ void cmd_ent0(char *entargs) /* Check some other permission type things. */ if (IsEmptyStr(newusername)) { - strcpy(newusername, CC->user.fullname); + strcpy(newusername, CCC->user.fullname); } - if ( (CC->user.axlevel < AxAideU) - && (strcasecmp(newusername, CC->user.fullname)) - && (strcasecmp(newusername, CC->cs_inet_fn)) + if ( (CCC->user.axlevel < AxAideU) + && (strcasecmp(newusername, CCC->user.fullname)) + && (strcasecmp(newusername, CCC->cs_inet_fn)) ) { cprintf("%d You don't have permission to author messages as '%s'.\n", ERROR + HIGHER_ACCESS_REQUIRED, @@ -4345,13 +4365,13 @@ void cmd_ent0(char *entargs) } if (!IsEmptyStr(newuseremail)) { - if (!strcasecmp(newuseremail, CC->cs_inet_email)) { + if (!strcasecmp(newuseremail, CCC->cs_inet_email)) { newuseremail_ok = 1; } - else if (!IsEmptyStr(CC->cs_inet_other_emails)) { - j = num_tokens(CC->cs_inet_other_emails, '|'); + else if (!IsEmptyStr(CCC->cs_inet_other_emails)) { + j = num_tokens(CCC->cs_inet_other_emails, '|'); for (i=0; ics_inet_other_emails, i, '|', sizeof buf); + extract_token(buf, CCC->cs_inet_other_emails, i, '|', sizeof buf); if (!strcasecmp(newuseremail, buf)) { newuseremail_ok = 1; } @@ -4367,7 +4387,7 @@ void cmd_ent0(char *entargs) return; } - CC->cs_flags |= CS_POSTING; + CCC->cs_flags |= CS_POSTING; /* In mailbox rooms we have to behave a little differently -- * make sure the user has specified at least one recipient. Then @@ -4376,10 +4396,10 @@ void cmd_ent0(char *entargs) * is the DRAFTS room which does not require recipients */ - if ( ( ( (CC->room.QRflags & QR_MAILBOX) && (!strcasecmp(&CC->room.QRname[11], MAILROOM)) ) - || ( (CC->room.QRflags & QR_MAILBOX) && (CC->curr_view == VIEW_MAILBOX) ) - ) && (strcasecmp(&CC->room.QRname[11], USERDRAFTROOM)) !=0 ) { - if (CC->user.axlevel < AxProbU) { + if ( ( ( (CCC->room.QRflags & QR_MAILBOX) && (!strcasecmp(&CCC->room.QRname[11], MAILROOM)) ) + || ( (CCC->room.QRflags & QR_MAILBOX) && (CCC->curr_view == VIEW_MAILBOX) ) + ) && (strcasecmp(&CCC->room.QRname[11], USERDRAFTROOM)) !=0 ) { + if (CCC->user.axlevel < AxProbU) { strcpy(recp, "sysop"); strcpy(cc, ""); strcpy(bcc, ""); @@ -4419,7 +4439,7 @@ void cmd_ent0(char *entargs) } if (valid_to->num_internet + valid_cc->num_internet + valid_bcc->num_internet > 0) { - if (CtdlCheckInternetMailPermission(&CC->user)==0) { + if (CtdlCheckInternetMailPermission(&CCC->user)==0) { cprintf("%d You do not have permission " "to send Internet mail.\n", ERROR + HIGHER_ACCESS_REQUIRED); @@ -4431,7 +4451,7 @@ void cmd_ent0(char *entargs) } if ( ( (valid_to->num_internet + valid_to->num_ignet + valid_cc->num_internet + valid_cc->num_ignet + valid_bcc->num_internet + valid_bcc->num_ignet) > 0) - && (CC->user.axlevel < AxNetU) ) { + && (CCC->user.axlevel < AxNetU) ) { cprintf("%d Higher access required for network mail.\n", ERROR + HIGHER_ACCESS_REQUIRED); free_recipients(valid_to); @@ -4442,8 +4462,8 @@ void cmd_ent0(char *entargs) if ((RESTRICT_INTERNET == 1) && (valid_to->num_internet + valid_cc->num_internet + valid_bcc->num_internet > 0) - && ((CC->user.flags & US_INTERNET) == 0) - && (!CC->internal_pgm)) { + && ((CCC->user.flags & US_INTERNET) == 0) + && (!CCC->internal_pgm)) { cprintf("%d You don't have access to Internet mail.\n", ERROR + HIGHER_ACCESS_REQUIRED); free_recipients(valid_to); @@ -4456,16 +4476,16 @@ void cmd_ent0(char *entargs) /* Is this a room which has anonymous-only or anonymous-option? */ anonymous = MES_NORMAL; - if (CC->room.QRflags & QR_ANONONLY) { + if (CCC->room.QRflags & QR_ANONONLY) { anonymous = MES_ANONONLY; } - if (CC->room.QRflags & QR_ANONOPT) { + if (CCC->room.QRflags & QR_ANONOPT) { if (anon_flag == 1) { /* only if the user requested it */ anonymous = MES_ANONOPT; } } - if ((CC->room.QRflags & QR_MAILBOX) == 0) { + if ((CCC->room.QRflags & QR_MAILBOX) == 0) { recp[0] = 0; } @@ -4473,7 +4493,7 @@ void cmd_ent0(char *entargs) * strongly recommended in this room, if either the SUBJECTREQ flag * is set, or if there is one or more Internet email recipients. */ - if (CC->room.QRflags2 & QR2_SUBJECTREQ) subject_required = 1; + if (CCC->room.QRflags2 & QR2_SUBJECTREQ) subject_required = 1; if ((valid_to) && (valid_to->num_internet > 0)) subject_required = 1; if ((valid_cc) && (valid_cc->num_internet > 0)) subject_required = 1; if ((valid_bcc) && (valid_bcc->num_internet > 0)) subject_required = 1; @@ -4503,8 +4523,8 @@ void cmd_ent0(char *entargs) cprintf("%d send message\n", SEND_LISTING); } - msg = CtdlMakeMessage(&CC->user, recp, cc, - CC->room.QRname, anonymous, format_type, + msg = CtdlMakeMessage(&CCC->user, recp, cc, + CCC->room.QRname, anonymous, format_type, newusername, newuseremail, subject, ((!IsEmptyStr(supplied_euid)) ? supplied_euid : NULL), NULL, references); @@ -4536,14 +4556,24 @@ void cmd_ent0(char *entargs) if (msg != NULL) { msgnum = CtdlSubmitMsg(msg, valid, "", QP_EADDR); + if (verbose_reply) + { + if (StrLength(CCC->StatusMessage)>0) + { + StrBufAppendBufPlain(CCC->StatusMessage, HKEY("\n000\n"), 0); + cputbuf(CCC->StatusMessage); + } + else + client_write(HKEY("\n000\n")); + } if (do_confirm) { cprintf("%ld\n", msgnum); if (msgnum >= 0L) { - cprintf("Message accepted.\n"); + client_write(HKEY("Message accepted.\n")); } else { - cprintf("Internal error.\n"); + client_write(HKEY("Internal error.\n")); } if (msg->cm_fields['E'] != NULL) { cprintf("%s\n", msg->cm_fields['E']);