X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=citadel%2Fmodules%2Fimap%2Fimap_fetch.c;h=293fecca019eec5c160b7c7531a63cfd4c32f818;hp=3f00d3f3f65c26380005589c3fc8d8d21bb1d37d;hb=5ac2920028e92a453c686c799327d7a66b3e7b49;hpb=80172bd70dde62001e0779f39efd4ad9835788d9 diff --git a/citadel/modules/imap/imap_fetch.c b/citadel/modules/imap/imap_fetch.c index 3f00d3f3f..293fecca0 100644 --- a/citadel/modules/imap/imap_fetch.c +++ b/citadel/modules/imap/imap_fetch.c @@ -2,21 +2,17 @@ * Implements the FETCH command in IMAP. * This is a good example of the protocol's gratuitous complexity. * - * Copyright (c) 2001-2011 by the citadel.org team + * Copyright (c) 2001-2020 by the citadel.org team * - * This program is open source software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. + * This program is open source software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. */ @@ -145,8 +141,7 @@ void imap_fetch_rfc822(long msgnum, const char *whichfmt) { * us to fetch the message body from disk. If not, we can save * on some disk operations... */ - if ( (!strcasecmp(whichfmt, "RFC822")) - || (!strcasecmp(whichfmt, "RFC822.TEXT")) ) { + if ( (!strcasecmp(whichfmt, "RFC822")) || (!strcasecmp(whichfmt, "RFC822.TEXT")) ) { need_body = 1; } @@ -192,7 +187,9 @@ void imap_fetch_rfc822(long msgnum, const char *whichfmt) { (need_body ? HEADERS_ALL : HEADERS_FAST), 0, 1, NULL, SUPPRESS_ENV_TO, NULL, NULL, NULL ); - if (!need_body) IAPuts("\r\n"); /* extra trailing newline */ + if (!need_body) { + client_write(HKEY("\r\n")); // extra trailing newline -- to the redirect_buffer, *not* to the client + } Imap->cached_rfc822 = CCC->redirect_buffer; CCC->redirect_buffer = NULL; Imap->cached_rfc822_msgnum = msgnum; @@ -233,16 +230,11 @@ void imap_fetch_rfc822(long msgnum, const char *whichfmt) { FreeStrBuf(&Line); } else { - headers_size = - total_size = StrLength(Imap->cached_rfc822); + headers_size = total_size = StrLength(Imap->cached_rfc822); text_size = 0; } - IMAP_syslog(LOG_DEBUG, - "RFC822: headers=" SIZE_T_FMT - ", text=" SIZE_T_FMT - ", total=" SIZE_T_FMT, - headers_size, text_size, total_size); + syslog(LOG_DEBUG, "imap: RFC822 headers=" SIZE_T_FMT ", text=" SIZE_T_FMT ", total=" SIZE_T_FMT, headers_size, text_size, total_size); if (!strcasecmp(whichfmt, "RFC822.SIZE")) { IAPrintf("RFC822.SIZE " SIZE_T_FMT, total_size); @@ -269,7 +261,6 @@ void imap_fetch_rfc822(long msgnum, const char *whichfmt) { } - /* * Load a specific part of a message into the temp file to be output to a * client. FIXME we can handle parts like "2" and "2.1" and even "2.MIME" @@ -282,15 +273,11 @@ void imap_load_part(char *name, char *filename, char *partnum, char *disp, void *content, char *cbtype, char *cbcharset, size_t length, char *encoding, char *cbid, void *cbuserdata) { - struct CitContext *CCC = CC; char mimebuf2[SIZ]; StrBuf *desired_section; desired_section = (StrBuf *)cbuserdata; - IMAP_syslog(LOG_DEBUG, "imap_load_part() looking for %s, found %s", - ChrPtr(desired_section), - partnum - ); + syslog(LOG_DEBUG, "imap: imap_load_part() looking for %s, found %s", ChrPtr(desired_section), partnum); if (!strcasecmp(partnum, ChrPtr(desired_section))) { client_write(content, length); @@ -354,33 +341,26 @@ void imap_output_envelope_from(struct CtdlMessage *msg) { } /* For everything else, we do stuff. */ - IAPuts("(("); /* open double-parens */ - IPutMsgField(eAuthor); /* personal name */ - IAPuts(" NIL "); /* source route (not used) */ - + IAPuts("(("); // open double-parens + IPutMsgField(eAuthor); // display name + IAPuts(" NIL "); // source route (not used) if (!CM_IsEmpty(msg, erFc822Addr)) { process_rfc822_addr(msg->cm_fields[erFc822Addr], user, node, name); - IPutStr(user, strlen(user)); /* mailbox name (user id) */ + IPutStr(user, strlen(user)); /* mailbox name (user id) */ IAPuts(" "); - if (!strcasecmp(node, config.c_nodename)) { - IPutStr(CFG_KEY(c_fqdn)); - } - else { - IPutStr(node, strlen(node)); /* host name */ - } + IPutStr(node, strlen(node)); /* host name */ } else { - IPutMsgField(eAuthor); /* mailbox name (user id) */ + IPutMsgField(eAuthor); /* Make up a synthetic address */ IAPuts(" "); - IPutMsgField(eNodeName); /* host name */ + IPutStr(CtdlGetConfigStr("c_fqdn"), strlen(CtdlGetConfigStr("c_fqdn"))); } IAPuts(")) "); /* close double-parens */ } - /* * Output an envelope address (or set of addresses) in the official, * convoluted, braindead format. (Note that we can't use this for @@ -451,8 +431,7 @@ void imap_fetch_envelope(struct CtdlMessage *msg) { else { msgdate = time(NULL); } - len = datestring(datestringbuf, sizeof datestringbuf, - msgdate, DATESTRING_IMAP); + len = datestring(datestringbuf, sizeof datestringbuf, msgdate, DATESTRING_IMAP); /* Now start spewing data fields. The order is important, as it is * defined by the protocol specification. Nonexistent fields must @@ -521,10 +500,9 @@ void imap_fetch_envelope(struct CtdlMessage *msg) { len = msg->cm_lengths[emessageId]; if ((len == 0) || ( - (msg->cm_fields[emessageId][0] == '<') && - (msg->cm_fields[emessageId][len - 1] == '>')) - ) - { + (msg->cm_fields[emessageId][0] == '<') && + (msg->cm_fields[emessageId][len - 1] == '>')) + ) { IPutMsgField(emessageId); } else @@ -551,6 +529,7 @@ void imap_fetch_envelope(struct CtdlMessage *msg) { IAPuts(")"); } + /* * This function is called only when CC->redirect_buffer contains a set of * RFC822 headers with no body attached. Its job is to strip that set of @@ -670,9 +649,7 @@ void imap_fetch_body(long msgnum, ConstStr item, int is_peek) { if (strchr(ChrPtr(section), '[') != NULL) { StrBufStripAllBut(section, '[', ']'); } - IMAP_syslog(LOG_DEBUG, "Section is: [%s]", - (StrLength(section) == 0) ? "(empty)" : ChrPtr(section) - ); + syslog(LOG_DEBUG, "imap: selected section is [%s]", (StrLength(section) == 0) ? "(empty)" : ChrPtr(section)); /* Burn the cache if we don't have the same section of the * same message again. @@ -704,13 +681,13 @@ void imap_fetch_body(long msgnum, ConstStr item, int is_peek) { is_partial = 1; } if ( (is_partial == 1) && (StrLength(partial) > 0) ) { - IMAP_syslog(LOG_DEBUG, "Partial is <%s>", ChrPtr(partial)); + syslog(LOG_DEBUG, "imap: selected partial is <%s>", ChrPtr(partial)); } if (Imap->cached_body == NULL) { CCC->redirect_buffer = NewStrBufPlain(NULL, SIZ); loading_body_now = 1; - msg = CtdlFetchMessage(msgnum, (need_body ? 1 : 0)); + msg = CtdlFetchMessage(msgnum, (need_body ? 1 : 0), 1); } /* Now figure out what the client wants, and get it */ @@ -1085,7 +1062,7 @@ void imap_do_fetch_msg(int seq, citimap_command *Cmd) { msg = NULL; } if (msg == NULL) { - msg = CtdlFetchMessage(Imap->msgids[seq-1], 1); + msg = CtdlFetchMessage(Imap->msgids[seq-1], 1, 1); body_loaded = 1; } imap_fetch_bodystructure(Imap->msgids[seq-1], @@ -1093,14 +1070,14 @@ void imap_do_fetch_msg(int seq, citimap_command *Cmd) { } else if (!strcasecmp(Cmd->Params[i].Key, "ENVELOPE")) { if (msg == NULL) { - msg = CtdlFetchMessage(Imap->msgids[seq-1], 0); + msg = CtdlFetchMessage(Imap->msgids[seq-1], 0, 1); body_loaded = 0; } imap_fetch_envelope(msg); } else if (!strcasecmp(Cmd->Params[i].Key, "INTERNALDATE")) { if (msg == NULL) { - msg = CtdlFetchMessage(Imap->msgids[seq-1], 0); + msg = CtdlFetchMessage(Imap->msgids[seq-1], 0, 1); body_loaded = 0; } imap_fetch_internaldate(msg); @@ -1129,16 +1106,16 @@ void imap_do_fetch(citimap_command *Cmd) { /* debug output the parsed vector */ { int i; - IMAP_syslog(LOG_DEBUG, "----- %ld params", Cmd->num_parms); + syslog(LOG_DEBUG, "imap: ----- %ld params", Cmd->num_parms); for (i=0; i < Cmd->num_parms; i++) { if (Cmd->Params[i].len != strlen(Cmd->Params[i].Key)) - IMAP_syslog(LOG_DEBUG, "*********** %ld != %ld : %s", + syslog(LOG_DEBUG, "imap: *********** %ld != %ld : %s", Cmd->Params[i].len, strlen(Cmd->Params[i].Key), Cmd->Params[i].Key); else - IMAP_syslog(LOG_DEBUG, "%ld : %s", + syslog(LOG_DEBUG, "imap: %ld : %s", Cmd->Params[i].len, Cmd->Params[i].Key); }} @@ -1461,7 +1438,7 @@ void imap_uidfetch(int num_parms, ConstStr *Params) { MakeStringOf(Cmd.CmdBuf, 4); #if 0 - IMAP_syslog(LOG_DEBUG, "-------%s--------", ChrPtr(Cmd.CmdBuf)); + syslog(LOG_DEBUG, "imap: -------%s--------", ChrPtr(Cmd.CmdBuf)); #endif num_items = imap_extract_data_items(&Cmd); if (num_items < 1) {