network_spool_msg() handle QP
authorWilfried Goesgens <dothebart@citadel.org>
Fri, 12 Aug 2011 15:51:14 +0000 (15:51 +0000)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 4 Sep 2011 21:46:06 +0000 (21:46 +0000)
while appending the [roomname] to the mailsubject, we have to
  - de-qp the original subject
  - search for the roomname
  - possibly prepend '[roomame] '
  - and re-qp everything.
that way we solve...
  - multiple [roomname] additions in case of QP encoded subjects
  - non RFC-Conformant behaviour in case of roomnames with umlauts.

citadel/modules/network/serv_network.c

index 1187cfe58a9909ffbd669b41d93cd86ef13daad4..9115b1fb4ee611620824b2c5d7031ac1a7c479da 100644 (file)
@@ -679,8 +679,9 @@ void network_spool_msg(long msgnum, void *userdata) {
                 */
                msg = CtdlFetchMessage(msgnum, 1);
                if (msg != NULL) {
-                       int len, rlen;
+                       int rlen;
                        char *pCh;
+                       StrBuf *Subject, *FlatSubject;
 
                        if (msg->cm_fields['V'] == NULL){
                                /* local message, no enVelope */
@@ -709,27 +710,37 @@ void network_spool_msg(long msgnum, void *userdata) {
 
                        /* Prepend "[List name]" to the subject */
                        if (msg->cm_fields['U'] == NULL) {
-                               msg->cm_fields['U'] = strdup("(no subject)");
+                               Subject = NewStrBufPlain(HKEY("(no subject)"));
                        }
-                       
-                       len  = strlen(msg->cm_fields['U']);
+                       else {
+                               Subject = NewStrBufPlain(msg->cm_fields['U'], -1);
+                       }
+                       FlatSubject = NewStrBufPlain(NULL, StrLength(Subject));
+                       StrBuf_RFC822_to_Utf8(FlatSubject, Subject, NULL, NULL);
+
                        rlen = strlen(CC->room.QRname);
-                       pCh  = strstr(msg->cm_fields['U'], CC->room.QRname);
+                       pCh  = strstr(ChrPtr(FlatSubject), CC->room.QRname);
                        if ((pCh == NULL) ||
                            (*(pCh + rlen) != ']') ||
-                           (pCh == msg->cm_fields['U']) ||
+                           (pCh == ChrPtr(FlatSubject)) ||
                            (*(pCh - 1) != '[')
                                )
                        {
-                               char *pBuff;
+                               StrBuf *tmp;
+                               StrBufPlain(Subject, HKEY("["));
+                               StrBufAppendBufPlain(Subject, CC->room.QRname, rlen, 0);
+                               StrBufAppendBufPlain(Subject, HKEY("] "), 0);
+                               StrBufAppendBuf(Subject, FlatSubject, 0);
+                               tmp = Subject;  Subject = FlatSubject;  FlatSubject = tmp; /* so we can free the right one... */
+                               StrBufRFC2047encode(&Subject, FlatSubject);
+                       }
+                       
+                       if (msg->cm_fields['U'] != NULL)
+                               free (msg->cm_fields['U']);
+                       msg->cm_fields['U'] = SmashStrBuf(&Subject);
 
-                               rlen += len + 4;
-                               pBuff = malloc (rlen * sizeof(char));
+                       FreeStrBuf(&FlatSubject);
 
-                               snprintf(pBuff, rlen, "[%s] %s", CC->room.QRname, msg->cm_fields['U']);
-                               free(msg->cm_fields['U']);
-                               msg->cm_fields['U'] = pBuff;
-                       }
                        /* else we won't modify the buffer, since the roomname is already here. */
 
                        /* if we don't already have a 'reply to' field, put our roomname in. */