]> code.citadel.org Git - citadel.git/blobdiff - citadel/server/modules/rssclient/serv_rssclient.c
citadel.h is now citadel_defs.h
[citadel.git] / citadel / server / modules / rssclient / serv_rssclient.c
index 66d0d13a056c20cb5ebf341c5cc7bfbc74c7e580..07ea2e8181da82f6c8620a59c2751f1b3e333ba2 100644 (file)
@@ -19,7 +19,7 @@
 #include <expat.h>
 #include <curl/curl.h>
 #include <libcitadel.h>
-#include "../../citadel.h"
+#include "../../citadel_defs.h"
 #include "../../server.h"
 #include "../../citserver.h"
 #include "../../support.h"
@@ -126,37 +126,49 @@ void rss_end_element(void *data, const char *el) {
                        if (already_seen == 0) {
 
                                // Compose the message text
+
                                StrBuf *TheMessage = NewStrBuf();
-                               StrBufAppendPrintf(TheMessage,
-                                       "Content-type: text/html\n\n"
-                                       "\n\n"
-                                       "<html><head></head><body>"
-                               );
-               
+                               StrBufAppendPrintf(TheMessage, "<html><head></head><body>");
+
                                if (r->description != NULL) {
                                        StrBufAppendPrintf(TheMessage, "%s<br><br>\r\n", r->description);
                                        free(r->description);
                                        r->description = NULL;
                                }
-               
+
                                if (r->link != NULL) {
                                        StrBufAppendPrintf(TheMessage, "<a href=\"%s\">%s</a>\r\n", r->link, r->link);
                                        free(r->link);
                                        r->link = NULL;
                                }
-       
+
                                StrBufAppendPrintf(TheMessage, "</body></html>\r\n");
+
+                               // Quoted-Printable encode the HTML message, because RSS and Atom make no guarantee of line length limits.
+                               StrBuf *TheMessage_Encoded = StrBufQuotedPrintableEncode(TheMessage);
+
+                               // Now we reuse TheMessage -- this time it will contain the MIME headers concatenated with the encoded message.
+                               FlushStrBuf(TheMessage);
+                               StrBufAppendBufPlain(TheMessage, HKEY(
+                                       "Content-type: text/html; charset=UTF-8\r\n"
+                                       "Content-Transfer-Encoding: quoted-printable\r\n"
+                                       "\r\n"
+                                       ), 0
+                               );
+                               StrBufAppendBuf(TheMessage, TheMessage_Encoded, 0);
+                               FreeStrBuf(&TheMessage_Encoded);
+
                                CM_SetField(r->msg, eMesageText, ChrPtr(TheMessage), StrLength(TheMessage));
                                FreeStrBuf(&TheMessage);
-       
+
                                if (CM_IsEmpty(r->msg, eAuthor)) {
                                        CM_SetField(r->msg, eAuthor, HKEY("rss"));
                                }
-       
+
                                if (CM_IsEmpty(r->msg, eTimestamp)) {
                                        CM_SetFieldLONG(r->msg, eTimestamp, time(NULL));
                                }
-       
+
                                // Save it to the room(s)
                                struct rssroom *rr = NULL;
                                long msgnum = (-1);
@@ -173,7 +185,7 @@ void rss_end_element(void *data, const char *el) {
                        else {
                                syslog(LOG_DEBUG, "rssclient: already seen %s", r->item_id);
                        }
-       
+
                        CM_Free(r->msg);
                        r->msg = NULL;
                }