Experimental rfc822 output helper that folds lines
authorArt Cancro <ajc@citadel.org>
Tue, 4 Nov 2008 19:19:53 +0000 (19:19 +0000)
committerArt Cancro <ajc@citadel.org>
Tue, 4 Nov 2008 19:19:53 +0000 (19:19 +0000)
citadel/msgbase.c
citadel/sysdep.c
citadel/sysdep_decls.h

index 1d691ebb8f4c950797914158f5390583ad429676..e73121577d193345cdcd512a2314ba5c2293f141 100644 (file)
@@ -1794,7 +1794,7 @@ int CtdlOutputPreLoadedMsg(
                                else if (i == 'Y') {
                                        if ((flags & QP_EADDR) != 0) 
                                                mptr = qp_encode_email_addrs(mptr);
-                                       cprintf("CC: %s%s", mptr, nl);
+                                       fold_cprintf("CC: %s%s", mptr, nl);
                                }
                                else if (i == 'P') {
                                        cprintf("Return-Path: %s%s", mptr, nl);
@@ -1824,13 +1824,13 @@ int CtdlOutputPreLoadedMsg(
                                {
                                        if (haschar(mptr, '@') == 0)
                                        {
-                                               cprintf("To: %s@%s%s", mptr, config.c_fqdn, nl);
+                                               fold_cprintf("To: %s@%s%s", mptr, config.c_fqdn, nl);
                                        }
                                        else
                                        {
                                                if ((flags & QP_EADDR) != 0) 
                                                        mptr = qp_encode_email_addrs(mptr);
-                                               cprintf("To: %s%s", mptr, nl);
+                                               fold_cprintf("To: %s%s", mptr, nl);
                                        }
                                }
                                else if (i == 'T') {
index d79785a5a5ebebf1d9dc93473ec9dce08f9eafdc..975585c0fe1a897edfa8c4e4a7f5e4f72df1094a 100644 (file)
@@ -707,9 +707,8 @@ int client_write(char *buf, int nbytes)
 
 
 /*
- * cprintf()  ...   Send formatted printable data to the client.   It is
- *               implemented in terms of client_write() but remains in
- *               sysdep.c in case we port to somewhere without va_args...
+ * cprintf()   Send formatted printable data to the client.
+ *             Implemented in terms of client_write() so it's technically not sysdep...
  */
 void cprintf(const char *format, ...) {   
        va_list arg_ptr;   
@@ -723,6 +722,43 @@ void cprintf(const char *format, ...) {
 }   
 
 
+/*
+ * fold_cprintf()      Like cprintf() except it can do RFC2822-style header folding.
+ */
+void fold_cprintf(const char *format, ...) {   
+       va_list arg_ptr;   
+       char buf[4096];
+       int len;
+       char *bbuf;
+       char *ptr;
+   
+       va_start(arg_ptr, format);   
+       if (vsnprintf(buf, sizeof buf, format, arg_ptr) == -1)
+               buf[sizeof buf - 2] = '\n';
+       va_end(arg_ptr);
+
+       len = strlen(buf);
+       bbuf = buf;
+
+       while (len > 998) {
+               ptr = strchr(&bbuf[900], ',');
+               if (ptr == NULL) {
+                       ptr = bbuf+990;
+               }
+               if ((ptr - bbuf) > 990) {
+                       ptr = bbuf+990;
+               }
+               ++ptr;
+               client_write(bbuf, ptr-bbuf);
+               client_write("\r\n\t", 3);
+               len -= (ptr-bbuf);
+               bbuf = ptr++;
+       }
+
+       client_write(bbuf, len);
+}   
+
+
 /*
  * Read data from the client socket.
  * Return values are:
index 8a16f7305beb4915dfea149328c4c428a234118e..cf2b9c3ab5ead46a3e17687f1be35cf14458ce69 100644 (file)
 
 #ifdef __GNUC__
 void cprintf (const char *format, ...) __attribute__((__format__(__printf__,1,2)));
+void fold_cprintf (const char *format, ...) __attribute__((__format__(__printf__,1,2)));
 #else
 void cprintf (const char *format, ...);
+void fold_cprintf (const char *format, ...);
 #endif
 
 void CtdlLogPrintf(enum LogLevel loglevel, const char *format, ...);