more places where we can use cm_lengths;
authorWilfried Goesgens <dothebart@citadel.org>
Mon, 30 Sep 2013 22:16:05 +0000 (00:16 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Mon, 30 Sep 2013 22:16:05 +0000 (00:16 +0200)
quickie_message also needs to set this.

citadel/modules/ctdlproto/serv_messages.c
citadel/modules/extnotify/extnotify_main.c
citadel/modules/imap/imap_fetch.c
citadel/modules/imap/imap_search.c
citadel/modules/network/serv_netmail.c
citadel/modules/network/serv_netspool.c
citadel/modules/network/serv_network.c
citadel/modules/notes/serv_notes.c
citadel/modules/wiki/serv_wiki.c
citadel/msgbase.c

index f7ac4575e3d0e1a7162e93c7408400cdbd8b0590..e2fda42ce4ad26ddb026c094d73ad21a3b61bef7 100644 (file)
@@ -604,7 +604,7 @@ void cmd_ent0(char *entargs)
                 * to the actual mail address so others get a valid
                 * reply-to-header.
                 */
-               msg->cm_fields[eenVelopeTo] = strdup(valid->recp_orgroom);
+               CM_SetField(msg, eenVelopeTo, valid->recp_orgroom, strlen(valid->recp_orgroom));
        }
 
        if (msg != NULL) {
index 46c9ab8ea415cd206cdf643360c17ee99ab124c6..8eafc036a61b09e39fbbd54583cc2768dd59e10c 100644 (file)
@@ -351,7 +351,7 @@ void process_notify(long NotifyMsgnum, void *usrdata)
 
                        commandSiz = sizeof(config.c_pager_program) +
                                strlen(PagerNo) +
-                               strlen(msg->cm_fields[eExtnotify]) + 5;
+                               msg->cm_lengths[eExtnotify] + 5;
 
                        command = malloc(commandSiz);
 
index 407eed21fcbf2e2696a8c0bc5a35227eb1efcfa8..f9998937183a50652b1030986ec98440947497f7 100644 (file)
@@ -518,7 +518,7 @@ void imap_fetch_envelope(struct CtdlMessage *msg) {
        if (fieldptr != NULL) free(fieldptr);
 
        /* message ID */
-       len = strlen(msg->cm_fields[emessageId]);
+       len = msg->cm_lengths[emessageId];
        
        if ((len == 0) || (
                    (msg->cm_fields[emessageId][0] == '<') && 
index 0697441d50bc9403ce21e7e2361ace491bee67aa..cad499ceb63ad2091768ae552a5d8c99b2243758 100644 (file)
@@ -281,7 +281,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg,
                        need_to_free_msg = 1;
                }
                if (msg != NULL) {
-                       if (strlen(msg->cm_fields[eMesageText]) > atoi(itemlist[pos+1].Key)) {
+                       if (msg->cm_lengths[eMesageText] > atoi(itemlist[pos+1].Key)) {
                                match = 1;
                        }
                }
@@ -402,7 +402,7 @@ int imap_do_search_msg(int seq, struct CtdlMessage *supplied_msg,
                        need_to_free_msg = 1;
                }
                if (msg != NULL) {
-                       if (strlen(msg->cm_fields[eMesageText]) < atoi(itemlist[pos+1].Key)) {
+                       if (msg->cm_lengths[eMesageText] < atoi(itemlist[pos+1].Key)) {
                                match = 1;
                        }
                }
index b06da93f1a0e17461d31a0b88ee49a01db525089..c488388f9090735c0910c22cb5e07d40b7f11970 100644 (file)
@@ -136,8 +136,7 @@ static void ListCalculateSubject(struct CtdlMessage *msg)
                Subject = NewStrBufPlain(HKEY("(no subject)"));
        }
        else {
-               Subject = NewStrBufPlain(
-                       msg->cm_fields[eMsgSubject], -1);
+               Subject = NewStrBufPlain(CM_KEY(msg, eMsgSubject));
        }
        FlatSubject = NewStrBufPlain(NULL, StrLength(Subject));
        StrBuf_RFC822_to_Utf8(FlatSubject, Subject, NULL, NULL);
@@ -407,7 +406,7 @@ void network_process_participate(SpoolControl *sc, struct CtdlMessage *omsg, lon
                        ok_to_participate = 1;
                }
                
-               Buf = NewStrBufPlain(msg->cm_fields[eNodeName], -1);
+               Buf = NewStrBufPlain(CM_KEY(msg, eNodeName));
                if (CtdlIsValidNode(NULL,
                                    NULL,
                                    Buf,
index 5b90ef23d89f40510e98920e04bc9a1922dace9d..3dfec6375a9c379d4accf83812f327ae54ac2a0a 100644 (file)
@@ -462,7 +462,7 @@ void network_process_buffer(char *buffer, long size, HashList *working_ignetcfg,
                if (strcasecmp(msg->cm_fields[eDestination], config.c_nodename)) {
 
                        /* route the message */
-                       Buf = NewStrBufPlain(msg->cm_fields[eDestination], -1);
+                       Buf = NewStrBufPlain(CM_KEY(msg,eDestination));
                        if (CtdlIsValidNode(&nexthop, 
                                            NULL, 
                                            Buf, 
index 32bf49564a1f4f7b6f370df7eacf5abe4e3cdf15..ef9dfc56829fd4793e5a1cabea32427262087c19 100644 (file)
@@ -116,11 +116,11 @@ int network_usetable(struct CtdlMessage *msg)
        }
 
        /* Generate the message ID */
-       msgid = NewStrBufPlain(msg->cm_fields[emessageId], -1);
+       msgid = NewStrBufPlain(CM_KEY(msg, emessageId));
        if (haschar(ChrPtr(msgid), '@') == 0) {
                StrBufAppendBufPlain(msgid, HKEY("@"), 0);
                if (!CM_IsEmpty(msg, eNodeName)) {
-                       StrBufAppendBufPlain(msgid, msg->cm_fields[eNodeName], -1, 0);
+                       StrBufAppendBufPlain(msgid, CM_KEY(msg, eNodeName), 0);
                }
                else {
                        FreeStrBuf(&msgid);
index 839d5d537eb6ffa04e926aae200589004483a940..a250c8ccd63a652d7a317d1f33ad99ee7256a1c5 100644 (file)
@@ -107,7 +107,7 @@ int serv_notes_beforesave(struct CtdlMessage *msg, recptypes *recp)
         */
        strcpy(uuid, "");
        p = msg->cm_fields[eMesageText];
-       a = strlen(p);
+       a = msg->cm_lengths[eMesageText];
        while (--a > 0) {
                if (!strncasecmp(p, "X-KOrg-Note-Id: ", 16)) {  /* Found it */
                        safestrncpy(uuid, p + 16, sizeof(uuid));
@@ -152,7 +152,7 @@ int serv_notes_beforesave(struct CtdlMessage *msg, recptypes *recp)
        if ((v->summary) && (!IsEmptyStr(v->summary))) {
                CM_SetField(msg, eMsgSubject, v->summary, strlen(v->summary));
 
-               if (strlen(msg->cm_fields[eMsgSubject]) > 72) {
+               if (msg->cm_lengths[eMsgSubject] > 72) {
                        strcpy(&msg->cm_fields[eMsgSubject][68], "...");
                        CM_CutFieldAt(msg, eMsgSubject, 72);
                }
index e68055d05b8eda39c6077066f2e3884c2bd11bf7..ccfc77b7e66495e3c274d32a9a825798a6a1056f 100644 (file)
@@ -110,8 +110,8 @@ int wiki_upload_beforesave(struct CtdlMessage *msg, recptypes *recp) {
        /* Make sure we're saving a real wiki page rather than a wiki history page.
         * This is important in order to avoid recursing infinitely into this hook.
         */
-       if (    (strlen(msg->cm_fields[eExclusiveID]) >= 9)
-               && (!strcasecmp(&msg->cm_fields[eExclusiveID][strlen(msg->cm_fields[eExclusiveID])-9], "_HISTORY_"))
+       if (    (msg->cm_lengths[eExclusiveID] >= 9)
+               && (!strcasecmp(&msg->cm_fields[eExclusiveID][msg->cm_lengths[eExclusiveID]-9], "_HISTORY_"))
        ) {
                syslog(LOG_DEBUG, "History page not being historied\n");
                return(0);
@@ -152,13 +152,13 @@ int wiki_upload_beforesave(struct CtdlMessage *msg, recptypes *recp) {
 
        if (old_msg != NULL) {
                fp = fopen(diff_old_filename, "w");
-               rv = fwrite(old_msg->cm_fields[eMesageText], strlen(old_msg->cm_fields[eMesageText]), 1, fp);
+               rv = fwrite(old_msg->cm_fields[eMesageText], old_msg->cm_lengths[eMesageText], 1, fp);
                fclose(fp);
                CM_Free(old_msg);
        }
 
        fp = fopen(diff_new_filename, "w");
-       rv = fwrite(msg->cm_fields[eMesageText], strlen(msg->cm_fields[eMesageText]), 1, fp);
+       rv = fwrite(msg->cm_fields[eMesageText], msg->cm_lengths[eMesageText], 1, fp);
        fclose(fp);
 
        snprintf(diff_cmd, sizeof diff_cmd,
@@ -542,7 +542,7 @@ void wiki_rev(char *pagename, char *rev, char *operation)
        CtdlMakeTempFileName(temp, sizeof temp);
        fp = fopen(temp, "w");
        if (fp != NULL) {
-               r = fwrite(msg->cm_fields[eMesageText], strlen(msg->cm_fields[eMesageText]), 1, fp);
+               r = fwrite(msg->cm_fields[eMesageText], msg->cm_lengths[eMesageText], 1, fp);
                fclose(fp);
        }
        else {
index 23ca1a3c0f0fbdf895eee8ab22a08398c086abad..d1270f4d1e75b18b0fa9e744eed4e821d56663e9 100644 (file)
@@ -1592,13 +1592,13 @@ int CtdlOutputMsg(long msg_num,         /* message number (local) to fetch */
 
                if ((Author != NULL) && (*Author == NULL))
                {
-                       *Author = TheMessage->cm_fields[eAuthor];
-                       TheMessage->cm_fields[eAuthor] = NULL;
+                       long len;
+                       CM_GetAsField(TheMessage, eAuthor, Author, &len);
                }
                if ((Address != NULL) && (*Address == NULL))
                {       
-                       *Address = TheMessage->cm_fields[erFc822Addr];
-                       TheMessage->cm_fields[erFc822Addr] = NULL;
+                       long len;
+                       CM_GetAsField(TheMessage, erFc822Addr, Address, &len);
                }
                CM_Free(TheMessage);
                TheMessage = NULL;
@@ -1631,13 +1631,13 @@ int CtdlOutputMsg(long msg_num,         /* message number (local) to fetch */
                retcode = CtdlOutputPreLoadedMsg(TheMessage, mode, headers_only, do_proto, crlf, flags);
        if ((Author != NULL) && (*Author == NULL))
        {
-               *Author = TheMessage->cm_fields[eAuthor];
-               TheMessage->cm_fields[eAuthor] = NULL;
+               long len;
+               CM_GetAsField(TheMessage, eAuthor, Author, &len);
        }
        if ((Address != NULL) && (*Address == NULL))
        {       
-               *Address = TheMessage->cm_fields[erFc822Addr];
-               TheMessage->cm_fields[erFc822Addr] = NULL;
+               long len;
+               CM_GetAsField(TheMessage, erFc822Addr, Address, &len);
        }
 
        CM_Free(TheMessage);
@@ -2036,7 +2036,7 @@ int CtdlOutputPreLoadedMsg(
         * Pad it with spaces in order to avoid changing the RFC822 length of the message.
         */
        if ( (flags & SUPPRESS_ENV_TO) && (!CM_IsEmpty(TheMessage, eenVelopeTo)) ) {
-               memset(TheMessage->cm_fields[eenVelopeTo], ' ', strlen(TheMessage->cm_fields[eenVelopeTo]));
+               memset(TheMessage->cm_fields[eenVelopeTo], ' ', TheMessage->cm_lengths[eenVelopeTo]);
        }
                
        /* Are we downloading a MIME component? */
@@ -2456,7 +2456,7 @@ long send_message(struct CtdlMessage *msg) {
        struct ser_ret smr;
        int is_bigmsg = 0;
        char *holdM = NULL;
-       long oldMLen = 0;
+       long holdMLen = 0;
 
        /* Get a new message number */
        newmsgid = get_new_message_number();
@@ -2477,7 +2477,7 @@ long send_message(struct CtdlMessage *msg) {
                        is_bigmsg = 1;
                        holdM = msg->cm_fields[eMesageText];
                        msg->cm_fields[eMesageText] = NULL;
-                       oldMLen = msg->cm_lengths[eMesageText];
+                       holdMLen = msg->cm_lengths[eMesageText];
                        msg->cm_lengths[eMesageText] = 0;
                }
        }
@@ -2487,6 +2487,7 @@ long send_message(struct CtdlMessage *msg) {
 
        if (is_bigmsg) {
                msg->cm_fields[eMesageText] = holdM;
+               msg->cm_lengths[eMesageText] = holdMLen;
        }
 
        if (smr.len == 0) {
@@ -2506,7 +2507,7 @@ long send_message(struct CtdlMessage *msg) {
                                  &newmsgid,
                                  (int)sizeof(long),
                                  holdM,
-                                 (oldMLen + 1)
+                                 (holdMLen + 1)
                                );
                }
                retval = newmsgid;
@@ -2965,29 +2966,31 @@ void quickie_message(const char *from,
        msg->cm_format_type = format_type;
 
        if (from != NULL) {
-               msg->cm_fields[eAuthor] = strdup(from);
+               CM_SetField(msg, eAuthor, from, strlen(from));
        }
        else if (fromaddr != NULL) {
-               msg->cm_fields[eAuthor] = strdup(fromaddr);
-               if (strchr(msg->cm_fields[eAuthor], '@')) {
-                       *strchr(msg->cm_fields[eAuthor], '@') = 0;
+               char *pAt;
+               CM_SetField(msg, eAuthor, fromaddr, strlen(fromaddr));
+               pAt = strchr(msg->cm_fields[eAuthor], '@');
+               if (pAt != NULL) {
+                       CM_CutFieldAt(msg, eAuthor, pAt - msg->cm_fields[eAuthor]);
                }
        }
        else {
                msg->cm_fields[eAuthor] = strdup("Citadel");
        }
 
-       if (fromaddr != NULL) msg->cm_fields[erFc822Addr] = strdup(fromaddr);
-       if (room != NULL) msg->cm_fields[eOriginalRoom] = strdup(room);
-       msg->cm_fields[eNodeName] = strdup(NODENAME);
+       if (fromaddr != NULL) CM_SetField(msg, erFc822Addr, fromaddr, strlen(fromaddr));
+       if (room != NULL) CM_SetField(msg, eOriginalRoom, room, strlen(room));
+       CM_SetField(msg, eNodeName, NODENAME, strlen(NODENAME));
        if (to != NULL) {
-               msg->cm_fields[eRecipient] = strdup(to);
+               CM_SetField(msg, eRecipient, to, strlen(to));
                recp = validate_recipients(to, NULL, 0);
        }
        if (subject != NULL) {
-               msg->cm_fields[eMsgSubject] = strdup(subject);
+               CM_SetField(msg, eMsgSubject, subject, strlen(subject));
        }
-       msg->cm_fields[eMesageText] = strdup(text);
+       CM_SetField(msg, eMesageText, text, strlen(text));
 
        CtdlSubmitMsg(msg, recp, room, 0);
        CM_Free(msg);