]> code.citadel.org Git - citadel.git/commitdiff
* moved CtdlDecodeQuotedPrintable() into tools.c
authorArt Cancro <ajc@citadel.org>
Sun, 11 Nov 2007 04:46:40 +0000 (04:46 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 11 Nov 2007 04:46:40 +0000 (04:46 +0000)
  (later we will move most or all of tools.c into libcitadel)
* amended citadel_ipc.c message reading loop.  When using MSG4 (nearly
  always), parse base64 and quoted-printable encodings, and decode them.
  MSG4 does not *yet* send these, instead performing the decoding on
  the server side.  During experimentation I told the server not to
  decode, and this will resolve Bug #289.  All that's left to do is to
  add something to the protocol so that the client can tell the server
  that it wants non-decoded message text.  I'll do that tomorrow.

citadel/citadel_ipc.c
citadel/mime_parser.c
citadel/tools.c
citadel/tools.h
webcit/mime_parser.c
webcit/tools.c
webcit/webcit.h

index d40b837d61d00318ea4fa168143bb9479e9cba8c..0a16b3107ce30be969d1ba8134c690c0724e4578 100644 (file)
@@ -477,6 +477,7 @@ int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime,
        size_t bbb_len;
        int multipart_hunting = 0;
        char multipart_prefix[128];
+       char encoding[256];
 
        if (!cret) return -1;
        if (!mret) return -1;
@@ -484,6 +485,7 @@ int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime,
        if (!*mret) return -1;
        if (!msgnum) return -1;
 
+       strcpy(encoding, "");
        strcpy(mret[0]->content_type, "");
        sprintf(aaa, "MSG%d %ld|%d", as_mime, msgnum, headers);
        ret = CtdlIPCGenericCommand(ipc, aaa, NULL, 0, &bbb, &bbb_len, cret);
@@ -596,6 +598,11 @@ int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime,
                                                strcpy(mret[0]->mime_chosen, &mret[0]->mime_chosen[23]);
                                                striplt(mret[0]->mime_chosen);
                                        }
+                                       if (!strncasecmp(bbb, "Content-transfer-encoding:", 26)) {
+                                               extract_token(encoding, bbb, 0, '\n', sizeof encoding);
+                                               strcpy(encoding, &encoding[26]);
+                                               striplt(encoding);
+                                       }
                                        remove_token(bbb, 0, '\n');
                                } while ((bbb[0] != 0) && (bbb[0] != '\n'));
                                remove_token(bbb, 0, '\n');
@@ -604,8 +611,25 @@ int CtdlIPCGetSingleMessage(CtdlIPC *ipc, long msgnum, int headers, int as_mime,
 
                }
                if (strlen(bbb)) {
+
+                       if ( (!strcasecmp(encoding, "base64")) || (!strcasecmp(encoding, "quoted-printable")) ) {
+                               char *ccc = NULL;
+                               int bytes_decoded = 0;
+                               ccc = malloc(strlen(bbb) + 32768);
+                               if (!strcasecmp(encoding, "base64")) {
+                                       bytes_decoded = CtdlDecodeBase64(ccc, bbb, strlen(bbb));
+                               }
+                               else if (!strcasecmp(encoding, "quoted-printable")) {
+                                       bytes_decoded = CtdlDecodeQuotedPrintable(ccc, bbb, strlen(bbb));
+                               }
+                               ccc[bytes_decoded] = 0;
+                               free(bbb);
+                               bbb = ccc;
+                       }
+
                        /* FIXME: Strip trailing whitespace */
                        bbb = (char *)realloc(bbb, (size_t)(strlen(bbb) + 1));
+
                } else {
                        bbb = (char *)realloc(bbb, 1);
                        *bbb = '\0';
index 9569d68eb07f4f9c8c2fc42d40b8a3bfa6a0a1ae..a1a4965e945b7c7f5e6c011972dd5af5157ebd62 100644 (file)
@@ -74,43 +74,6 @@ char *fixed_partnum(char *supplied_partnum) {
 
 
 
-/*
- * Convert "quoted-printable" to binary.  Returns number of bytes decoded.
- * according to RFC2045 section 6.7
- */
-int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen) {
-       unsigned int ch;
-       int decoded_length = 0;
-       int pos = 0;
-
-       while (pos < sourcelen)
-       {
-               if (!strncmp(&encoded[pos], "=\r\n", 3))
-               {
-                       pos += 3;
-               }
-               else if (!strncmp(&encoded[pos], "=\n", 2))
-               {
-                       pos += 2;
-               }
-               else if (encoded[pos] == '=')
-               {
-                       ch = 0;
-                       sscanf(&encoded[pos+1], "%02x", &ch);
-                       pos += 3;
-                       decoded[decoded_length++] = ch;
-               }
-               else
-               {
-                       decoded[decoded_length++] = encoded[pos];
-                       pos += 1;
-               }
-       }
-       decoded[decoded_length] = 0;
-       return(decoded_length);
-}
-
-
 /*
  * Given a message or message-part body and a length, handle any necessary
  * decoding and pass the request up the stack.
index 725b9daed1508c20ef9d2cb9d203e9b4acb77095..b864642591c6cb205475f3e673129545ac81920b 100644 (file)
@@ -416,6 +416,43 @@ int CtdlDecodeBase64(char *dest, const char *source, size_t length)
     }
 }
 
+/*
+ * Convert "quoted-printable" to binary.  Returns number of bytes decoded.
+ * according to RFC2045 section 6.7
+ */
+int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen) {
+       unsigned int ch;
+       int decoded_length = 0;
+       int pos = 0;
+
+       while (pos < sourcelen)
+       {
+               if (!strncmp(&encoded[pos], "=\r\n", 3))
+               {
+                       pos += 3;
+               }
+               else if (!strncmp(&encoded[pos], "=\n", 2))
+               {
+                       pos += 2;
+               }
+               else if (encoded[pos] == '=')
+               {
+                       ch = 0;
+                       sscanf(&encoded[pos+1], "%02x", &ch);
+                       pos += 3;
+                       decoded[decoded_length++] = ch;
+               }
+               else
+               {
+                       decoded[decoded_length++] = encoded[pos];
+                       pos += 1;
+               }
+       }
+       decoded[decoded_length] = 0;
+       return(decoded_length);
+}
+
+
 /*
  * if we send out non ascii subjects, we encode it this way.
  */
index 4f205d6fa56b45419183672f3ffb6d321e8508d4..7c9f5c01728f8a36cd26c972bc3ac26e70619f3a 100644 (file)
@@ -9,6 +9,7 @@ unsigned long extract_unsigned_long(const char *source, int parmnum);
 void CtdlInitBase64Table(void);
 void CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen);
 int CtdlDecodeBase64(char *dest, const char *source, size_t length);
+int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
 void striplt(char *);
 int haschar(const char *st, int ch);
 void remove_token(char *source, int parmnum, char separator);
index d6a849ebd52b4b1a84a7dcfafe8975873d3e951d..c41fb26ad5cc628092c14a0e6c9b02690a762878 100644 (file)
@@ -61,43 +61,6 @@ char *fixed_partnum(char *supplied_partnum) {
 
 
 
-/*
- * Convert "quoted-printable" to binary.  Returns number of bytes decoded.
- * according to RFC2045 section 6.7
- */
-int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen) {
-       unsigned int ch;
-       int decoded_length = 0;
-       int pos = 0;
-
-       while (pos < sourcelen)
-       {
-               if (!strncmp(&encoded[pos], "=\r\n", 3))
-               {
-                       pos += 3;
-               }
-               else if (!strncmp(&encoded[pos], "=\n", 2))
-               {
-                       pos += 2;
-               }
-               else if (encoded[pos] == '=')
-               {
-                       ch = 0;
-                       sscanf(&encoded[pos+1], "%02x", &ch);
-                       pos += 3;
-                       decoded[decoded_length++] = ch;
-               }
-               else
-               {
-                       decoded[decoded_length++] = encoded[pos];
-                       pos += 1;
-               }
-       }
-       decoded[decoded_length] = 0;
-       return(decoded_length);
-}
-
-
 /*
  * Given a message or message-part body and a length, handle any necessary
  * decoding and pass the request up the stack.
index c7a4c099a3fc81c1b53250be3ea2fb319c9e11c8..591af0d977a0d73c101d8e9467be93ac9f92549a 100644 (file)
@@ -632,6 +632,43 @@ void generate_uuid(char *buf) {
 }
 
 
+/*
+ * Convert "quoted-printable" to binary.  Returns number of bytes decoded.
+ * according to RFC2045 section 6.7
+ */
+int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen) {
+       unsigned int ch;
+       int decoded_length = 0;
+       int pos = 0;
+
+       while (pos < sourcelen)
+       {
+               if (!strncmp(&encoded[pos], "=\r\n", 3))
+               {
+                       pos += 3;
+               }
+               else if (!strncmp(&encoded[pos], "=\n", 2))
+               {
+                       pos += 2;
+               }
+               else if (encoded[pos] == '=')
+               {
+                       ch = 0;
+                       sscanf(&encoded[pos+1], "%02x", &ch);
+                       pos += 3;
+                       decoded[decoded_length++] = ch;
+               }
+               else
+               {
+                       decoded[decoded_length++] = encoded[pos];
+                       pos += 1;
+               }
+       }
+       decoded[decoded_length] = 0;
+       return(decoded_length);
+}
+
+
 /**
  * \brief Local replacement for controversial C library function that generates
  * names for temporary files.  Included to shut up compiler warnings.
index b10ed8ddce78fa0e29ef249010d81ab7cfccedb9..49fed8dc7ef9a39b67d659a4f0fba39520977699 100644 (file)
@@ -634,6 +634,7 @@ void calendar_summary_view(void);
 int load_msg_ptrs(char *servcmd, int with_headers);
 size_t CtdlEncodeBase64(char **dest, const char *source, size_t sourcelen, size_t *destlen, int linebreaks);
 int CtdlDecodeBase64(char *dest, const char *source, size_t length);
+int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen);
 void free_attachments(struct wcsession *sess);
 void free_march_list(struct wcsession *wcf);
 void set_room_policy(void);