]> code.citadel.org Git - citadel.git/blobdiff - citadel/server/internet_addressing.c
Fixed parsing of message-id angle brackets
[citadel.git] / citadel / server / internet_addressing.c
index b08123143c647ea2c95448422cb4dc075288241f..746bed1a0fb86d3c56bb6ec1843d3704f14eb5a1 100644 (file)
@@ -3,8 +3,7 @@
 //
 // Copyright (c) 1987-2024 by the citadel.org team
 //
-// This program is open source software.  Use, duplication, or disclosure
-// is subject to the terms of the GNU General Public License, version 3.
+// This program is open source software.  Use, duplication, or disclosure is subject to the GNU General Public License version 3.
 
 #include "sysdep.h"
 #include <stdlib.h>
@@ -88,7 +87,7 @@ int CtdlIsMe(char *addr, int addr_buf_len) {
        struct recptypes *recp;
        int i;
 
-       recp = validate_recipients(addr, NULL, 0);
+       recp = validate_recipients(addr, 0);
        if (recp == NULL) return(0);
 
        if (recp->num_local == 0) {
@@ -296,9 +295,8 @@ Array *split_recps(char *addresses, Array *append_to) {
 //
 // Caller needs to free the result using free_recipients()
 //
-struct recptypes *validate_recipients(char *supplied_recipients, const char *RemoteIdentifier, int Flags) {
+struct recptypes *validate_recipients(char *recipients_in, int Flags) {
        struct recptypes *ret;
-       char *recipients = NULL;
        char append[SIZ];
        long len;
        int mailtype;
@@ -314,14 +312,7 @@ struct recptypes *validate_recipients(char *supplied_recipients, const char *Rem
        if (ret == NULL) return(NULL);
        memset(ret, 0, sizeof(struct recptypes));                                       // set all values to null/zero
 
-       if (supplied_recipients == NULL) {
-               recipients = strdup("");
-       }
-       else {
-               recipients = strdup(supplied_recipients);
-       }
-
-       len = strlen(recipients) + 1024;                                                // allocate memory
+       len = strlen(recipients_in) + 1024;                                             // allocate memory
        ret->errormsg = malloc(len);
        ret->recp_local = malloc(len);
        ret->recp_internet = malloc(len);
@@ -337,7 +328,7 @@ struct recptypes *validate_recipients(char *supplied_recipients, const char *Rem
        ret->display_recp[0] = 0;
        ret->recptypes_magic = RECPTYPES_MAGIC;
 
-       Array *recp_array = split_recps(supplied_recipients, NULL);
+       Array *recp_array = split_recps(recipients_in, NULL);
 
        char *aliases = CtdlGetSysConfig(GLOBAL_ALIASES);                               // First hit the Global Alias Table
 
@@ -347,7 +338,7 @@ struct recptypes *validate_recipients(char *supplied_recipients, const char *Rem
                strncpy(this_recp, org_recp, sizeof this_recp);
 
                int i;
-               for (i=0; i<3; ++i) {                                           // pass three times through the aliaser
+               for (i=0; i<3; ++i) {                                                   // pass three times through the aliaser
                        mailtype = expand_aliases(this_recp, aliases);
        
                        // If an alias expanded to multiple recipients, strip off those recipients and append them
@@ -509,7 +500,6 @@ struct recptypes *validate_recipients(char *supplied_recipients, const char *Rem
                ret->num_local, ret->num_room, ret->num_internet, ret->num_error
        );
 
-       free(recipients);
        if (recp_array) {
                array_free(recp_array);
        }
@@ -676,12 +666,8 @@ void unfold_rfc822_field(char **field, char **FieldEnd)
 
        *FieldEnd = pFieldEnd;
        // convert non-space whitespace to spaces, and remove double blanks
-       for (sField = *field = pField; 
-            sField < pFieldEnd; 
-            pField++, sField++)
-       {
-               if ((*sField=='\r') || (*sField=='\n'))
-               {
+       for (sField = *field = pField; sField < pFieldEnd; pField++, sField++) {
+               if ((*sField=='\r') || (*sField=='\n')) {
                        int offset = 1;
                        while ( ( (*(sField + offset) == '\r') || (*(sField + offset) == '\n' )) && (sField + offset < pFieldEnd) ) {
                                offset ++;
@@ -697,8 +683,7 @@ void unfold_rfc822_field(char **field, char **FieldEnd)
                                        pField++;
                                        sField++;
                                        
-                                       while ((sField < pFieldEnd) && 
-                                              isspace(*sField))
+                                       while ((sField < pFieldEnd) && isspace(*sField))
                                                sField++;
                                        *pField = *sField;
                                }
@@ -902,26 +887,19 @@ int convert_field(struct CtdlMessage *msg, const char *beg, const char *end) {
                        syslog(LOG_WARNING, "internet_addressing: duplicate message id");
                }
                else {
-                       char *pValue;
-                       long pValueLen;
-
-                       pValue = value;
-                       pValueLen = valuelen;
-                       // Strip angle brackets
-                       while (haschar(pValue, '<') > 0) {
-                               pValue ++;
-                               pValueLen --;
-                       }
-
-                       for (i = 0; i <= pValueLen; ++i)
-                               if (pValue[i] == '>') {
-                                       pValueLen = i;
-                                       break;
+                       char *pvalue = value;                           // strip out angle brackets
+                       char *ptr = pvalue;
+                       while (*ptr) {
+                               if (*ptr == '<') {
+                                       pvalue = ptr + 1;
                                }
-
-                       CM_SetField(msg, emessageId, pValue);
+                               if (*ptr == '>') {
+                                       *ptr = 0;
+                               }
+                               ++ptr;
+                       }
+                       CM_SetField(msg, emessageId, pvalue);
                }
-
                processed = 1;
        }
 
@@ -953,8 +931,6 @@ int convert_field(struct CtdlMessage *msg, const char *beg, const char *end) {
                processed = 1;
        }
 
-
-
        // Clean up and move on.
        free(key);      // Don't free 'value', it's actually the same buffer
        return processed;
@@ -1049,7 +1025,6 @@ struct CtdlMessage *convert_internet_message_buf(StrBuf **rfc822) {
                        }
 
                        ++pos;
-
                }
 
                // At this point we have a field.  Are we interested in it?
@@ -1066,10 +1041,11 @@ struct CtdlMessage *convert_internet_message_buf(StrBuf **rfc822) {
                        alldone = 1;
        }
        StrBufAppendBufPlain(OtherHeaders, HKEY("\n"), 0);
-       if (pos < totalend)
+       if (pos < totalend) {
                StrBufAppendBufPlain(OtherHeaders, pos, totalend - pos, 0);
+       }
        FreeStrBuf(rfc822);
-       CM_SetAsFieldSB(msg, eMesageText, &OtherHeaders);
+       CM_SetAsFieldSB(msg, eMessageText, &OtherHeaders);
 
        // Follow-up sanity checks...
 
@@ -1238,8 +1214,7 @@ int CtdlDirectoryLookup(char *target, char *internet_addr, size_t targbuflen) {
 }
 
 
-// Harvest any email addresses that someone might want to have in their
-// "collected addresses" book.
+// Harvest any email addresses that someone might want to have in their "collected addresses" book.
 char *harvest_collected_addresses(struct CtdlMessage *msg) {
        char *coll = NULL;
        char addr[256];