]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/imap/imap_fetch.c
fix type for sizeof; it shouldn't be the pointer.
[citadel.git] / citadel / modules / imap / imap_fetch.c
index 38de324e694091186eb5b2c415d5eed9598e8680..ed7f271651c79a7c71dc1801c8747fbfc7fd6240 100644 (file)
@@ -110,8 +110,8 @@ void imap_fetch_internaldate(struct CtdlMessage *msg) {
        time_t msgdate;
 
        if (!msg) return;
-       if (msg->cm_fields['T'] != NULL) {
-               msgdate = atol(msg->cm_fields['T']);
+       if (!CM_IsEmpty(msg, eTimestamp)) {
+               msgdate = atol(msg->cm_fields[eTimestamp]);
        }
        else {
                msgdate = time(NULL);
@@ -190,7 +190,7 @@ void imap_fetch_rfc822(long msgnum, const char *whichfmt) {
                CCC->redirect_buffer = NewStrBufPlain(NULL, SIZ);
                CtdlOutputMsg(msgnum, MT_RFC822,
                        (need_body ? HEADERS_ALL : HEADERS_FAST),
-                       0, 1, NULL, SUPPRESS_ENV_TO
+                       0, 1, NULL, SUPPRESS_ENV_TO, NULL, NULL
                );
                if (!need_body) IAPuts("\r\n"); /* extra trailing newline */
                Imap->cached_rfc822 = CCC->redirect_buffer;
@@ -209,8 +209,6 @@ void imap_fetch_rfc822(long msgnum, const char *whichfmt) {
         * intervening blank line to be part of the headers, not the text.
         */
        headers_size = 0;
-       text_size = 0;
-       total_size = 0;
 
        if (need_body) {
                StrBuf *Line = NewStrBuf();
@@ -357,12 +355,12 @@ void imap_output_envelope_from(struct CtdlMessage *msg) {
 
        /* For everything else, we do stuff. */
        IAPuts("(("); /* open double-parens */
-       plain_imap_strout(msg->cm_fields['A']); /* personal name */
+       plain_imap_strout(msg->cm_fields[eAuthor]);     /* personal name */
        IAPuts(" NIL ");        /* source route (not used) */
 
 
-       if (msg->cm_fields['F'] != NULL) {
-               process_rfc822_addr(msg->cm_fields['F'], user, node, name);
+       if (!CM_IsEmpty(msg, erFc822Addr)) {
+               process_rfc822_addr(msg->cm_fields[erFc822Addr], user, node, name);
                plain_imap_strout(user);                /* mailbox name (user id) */
                IAPuts(" ");
                if (!strcasecmp(node, config.c_nodename)) {
@@ -373,9 +371,9 @@ void imap_output_envelope_from(struct CtdlMessage *msg) {
                }
        }
        else {
-               plain_imap_strout(msg->cm_fields['A']); /* mailbox name (user id) */
+               plain_imap_strout(msg->cm_fields[eAuthor]); /* mailbox name (user id) */
                IAPuts(" ");
-               plain_imap_strout(msg->cm_fields['N']); /* host name */
+               plain_imap_strout(msg->cm_fields[eNodeName]);   /* host name */
        }
        
        IAPuts(")) "); /* close double-parens */
@@ -447,8 +445,8 @@ void imap_fetch_envelope(struct CtdlMessage *msg) {
        if (!msg) return;
 
        /* Parse the message date into an IMAP-format date string */
-       if (msg->cm_fields['T'] != NULL) {
-               msgdate = atol(msg->cm_fields['T']);
+       if (!CM_IsEmpty(msg, eTimestamp)) {
+               msgdate = atol(msg->cm_fields[eTimestamp]);
        }
        else {
                msgdate = time(NULL);
@@ -468,14 +466,14 @@ void imap_fetch_envelope(struct CtdlMessage *msg) {
        IAPuts(" ");
 
        /* Subject */
-       plain_imap_strout(msg->cm_fields['U']);
+       plain_imap_strout(msg->cm_fields[eMsgSubject]);
        IAPuts(" ");
 
        /* From */
        imap_output_envelope_from(msg);
 
        /* Sender (default to same as 'From' if not present) */
-       fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Sender");
+       fieldptr = rfc822_fetch_field(msg->cm_fields[eMesageText], "Sender");
        if (fieldptr != NULL) {
                imap_output_envelope_addr(fieldptr);
                free(fieldptr);
@@ -485,7 +483,7 @@ void imap_fetch_envelope(struct CtdlMessage *msg) {
        }
 
        /* Reply-to */
-       fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Reply-to");
+       fieldptr = rfc822_fetch_field(msg->cm_fields[eMesageText], "Reply-to");
        if (fieldptr != NULL) {
                imap_output_envelope_addr(fieldptr);
                free(fieldptr);
@@ -495,53 +493,53 @@ void imap_fetch_envelope(struct CtdlMessage *msg) {
        }
 
        /* To */
-       imap_output_envelope_addr(msg->cm_fields['R']);
+       imap_output_envelope_addr(msg->cm_fields[eRecipient]);
 
        /* Cc (we do it this way because there might be a legacy non-Citadel Cc: field present) */
-       fieldptr = msg->cm_fields['Y'];
+       fieldptr = msg->cm_fields[eCarbonCopY];
        if (fieldptr != NULL) {
                imap_output_envelope_addr(fieldptr);
        }
        else {
-               fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Cc");
+               fieldptr = rfc822_fetch_field(msg->cm_fields[eMesageText], "Cc");
                imap_output_envelope_addr(fieldptr);
                if (fieldptr != NULL) free(fieldptr);
        }
 
        /* Bcc */
-       fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "Bcc");
+       fieldptr = rfc822_fetch_field(msg->cm_fields[eMesageText], "Bcc");
        imap_output_envelope_addr(fieldptr);
        if (fieldptr != NULL) free(fieldptr);
 
        /* In-reply-to */
-       fieldptr = rfc822_fetch_field(msg->cm_fields['M'], "In-reply-to");
+       fieldptr = rfc822_fetch_field(msg->cm_fields[eMesageText], "In-reply-to");
        plain_imap_strout(fieldptr);
        IAPuts(" ");
        if (fieldptr != NULL) free(fieldptr);
 
        /* message ID */
-       len = strlen(msg->cm_fields['I']);
+       len = strlen(msg->cm_fields[emessageId]);
        
        if ((len == 0) || (
-                   (msg->cm_fields['I'][0] == '<') && 
-                   (msg->cm_fields['I'][len - 1] == '>'))
+                   (msg->cm_fields[emessageId][0] == '<') && 
+                   (msg->cm_fields[emessageId][len - 1] == '>'))
                )
        {
-               plain_imap_strout(msg->cm_fields['I']);
+               plain_imap_strout(msg->cm_fields[emessageId]);
        }
        else 
        {
                char *Buf = malloc(len + 3);
                long pos = 0;
                
-               if (msg->cm_fields['I'][0] != '<')
+               if (msg->cm_fields[emessageId][0] != '<')
                {
                        Buf[pos] = '<';
                        pos ++;
                }
-               memcpy(&Buf[pos], msg->cm_fields['I'], len);
+               memcpy(&Buf[pos], msg->cm_fields[emessageId], len);
                pos += len;
-               if (msg->cm_fields['I'][len] != '>')
+               if (msg->cm_fields[emessageId][len] != '>')
                {
                        Buf[pos] = '>';
                        pos++;
@@ -604,7 +602,7 @@ void imap_strip_headers(StrBuf *section) {
                StrBufSipLine(Line, CCC->redirect_buffer, &Ptr);
 
                if (!isspace(ChrPtr(Line)[0])) {
-                       ok = 0;
+
                        if (doing_headers == 0) ok = 1;
                        else {
                                /* we're supposed to print all headers that are not matching the filter list */
@@ -754,7 +752,7 @@ void imap_fetch_body(long msgnum, ConstStr item, int is_peek) {
         * (Note value of 1 passed as 'dont_decode' so client gets it encoded)
         */
        else {
-               mime_parser(msg->cm_fields['M'], NULL,
+               mime_parser(msg->cm_fields[eMesageText], NULL,
                            *imap_load_part, NULL, NULL,
                            section,
                            1
@@ -792,7 +790,7 @@ void imap_fetch_body(long msgnum, ConstStr item, int is_peek) {
        iaputs(&Imap->cached_body[pstart], pbytes);
 
        if (msg != NULL) {
-               CtdlFreeMessage(msg);
+               CM_Free(msg);
        }
 
        /* Mark this message as "seen" *unless* this is a "peek" operation */
@@ -1021,7 +1019,7 @@ void imap_fetch_bodystructure (long msgnum, const char *item,
 
        /* For messages already stored in RFC822 format, we have to parse. */
        IAPuts("BODYSTRUCTURE ");
-       mime_parser(msg->cm_fields['M'],
+       mime_parser(msg->cm_fields[eMesageText],
                        NULL,
                        *imap_fetch_bodystructure_part, /* part */
                        *imap_fetch_bodystructure_pre,  /* pre-multi */
@@ -1086,7 +1084,7 @@ void imap_do_fetch_msg(int seq, citimap_command *Cmd) {
                 */
                else if (!strcasecmp(Cmd->Params[i].Key, "BODYSTRUCTURE")) {
                        if ((msg != NULL) && (!body_loaded)) {
-                               CtdlFreeMessage(msg);   /* need the whole thing */
+                               CM_Free(msg);   /* need the whole thing */
                                msg = NULL;
                        }
                        if (msg == NULL) {
@@ -1117,7 +1115,7 @@ void imap_do_fetch_msg(int seq, citimap_command *Cmd) {
        IAPuts(")\r\n");
        unbuffer_output();
        if (msg != NULL) {
-               CtdlFreeMessage(msg);
+               CM_Free(msg);
        }
 }