]> code.citadel.org Git - citadel.git/blobdiff - libcitadel/lib/stringbuf.c
* StrBufSanitizeEmailRecipientVector() fix bug cutting one of the email address
[citadel.git] / libcitadel / lib / stringbuf.c
index f4a43c3031b61080300ba0ef01af242d4a582286..fcbd1daa74b8091d7a202637b03745f29cc0b739 100644 (file)
@@ -2259,6 +2259,7 @@ int StrBufDecodeBase64(StrBuf *Buf)
        if (Buf == NULL) return -1;
 
        xferbuf = (char*) malloc(Buf->BufSize);
+       *xferbuf = '\0';
        siz = CtdlDecodeBase64(xferbuf,
                               Buf->buf,
                               Buf->BufUsed);
@@ -2546,14 +2547,15 @@ StrBuf *StrBufSanitizeEmailRecipientVector(const StrBuf *Recp,
                        else {
 
                                pch = EmailEnd + 1;
-                               while ((EmailEnd > UserStart) && 
+                               while ((EmailEnd > UserStart) && !gt &&
                                       ((*EmailEnd == ',') ||
                                        (*EmailEnd == '>') ||
                                        (isspace(*EmailEnd))))
                                {
                                        if (*EmailEnd == '>')
                                                gt = 1;
-                                       EmailEnd--;
+                                       else 
+                                               EmailEnd--;
                                }
                                if (EmailEnd == UserStart)
                                        break;
@@ -2569,6 +2571,7 @@ StrBuf *StrBufSanitizeEmailRecipientVector(const StrBuf *Recp,
                                At = strchr(EmailStart, '@');
                        }
                        else { /* this is a local recipient... no domain, just a realname */
+                               EmailStart = UserStart;
                                At = strchr(EmailStart, '@');
                                if (At == NULL) {
                                        UserEnd = EmailEnd;
@@ -2581,23 +2584,28 @@ StrBuf *StrBufSanitizeEmailRecipientVector(const StrBuf *Recp,
                        }
                }
 
-
-               if (UserStart != NULL)
+               if ((UserStart != NULL) && (UserEnd != NULL))
+                       StrBufPlain(UserName, UserStart, UserEnd - UserStart);
+               else if ((UserStart != NULL) && (UserEnd == NULL))
                        StrBufPlain(UserName, UserStart, UserEnd - UserStart);
                else
                        FlushStrBuf(UserName);
-               if (EmailStart != NULL)
+
+               if ((EmailStart != NULL) && (EmailEnd != NULL))
                        StrBufPlain(EmailAddress, EmailStart, EmailEnd - EmailStart);
+               else if ((EmailStart != NULL) && (EmailEnd == NULL))
+                       StrBufPlain(EmailAddress, EmailStart, EmailEnd - pche);
                else 
                        FlushStrBuf(EmailAddress);
 
                AddRecipient(Target, UserName, EmailAddress, EncBuf);
 
-
+               if (pch == NULL)
+                       break;
                
-               if (*pch == ',')
+               if ((pch != NULL) && (*pch == ','))
                        pch ++;
-               while (isspace(*pch))
+               if (pch != NULL) while (isspace(*pch))
                        pch ++;
        }
        return Target;