* msgbase.c: Added new API function CtdlOutputPreLoadedMsg(), and
authorArt Cancro <ajc@citadel.org>
Sun, 26 Nov 2000 05:24:22 +0000 (05:24 +0000)
committerArt Cancro <ajc@citadel.org>
Sun, 26 Nov 2000 05:24:22 +0000 (05:24 +0000)
  re-implemented the existing CtdlOutputMsg() as a wrapper around it.
* imap_fetch.c: used the above function to do all output pre-loaded

citadel/ChangeLog
citadel/imap_fetch.c
citadel/msgbase.c
citadel/msgbase.h

index bcf7b37d4a9329febb71fabfd655212838f3078b..fa43eb5747c8557f9778a5e810b2a24d0045c443 100644 (file)
@@ -1,4 +1,9 @@
  $Log$
+ Revision 573.30  2000/11/26 05:24:22  ajc
+ * msgbase.c: Added new API function CtdlOutputPreLoadedMsg(), and
+   re-implemented the existing CtdlOutputMsg() as a wrapper around it.
+ * imap_fetch.c: used the above function to do all output pre-loaded
+
  Revision 573.29  2000/11/25 09:36:18  error
  * Added a bit of detail to syslog entries; now shows session id attached to
    client, hostname, and username, and time the session ended.
@@ -2148,4 +2153,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
-
index 0cb319fcbf91a59cdc3915aa6ea8de3d76f3659c..9b653b85f6073e0f7ed23d20144b62a9075bb70c 100644 (file)
@@ -88,7 +88,7 @@ void imap_fetch_internaldate(struct CtdlMessage *msg) {
  *     "RFC822.SIZE"   size of translated message
  *     "RFC822.TEXT"   body only (without leading blank line)
  */
-void imap_fetch_rfc822(int msgnum, char *whichfmt) {
+void imap_fetch_rfc822(int msgnum, char *whichfmt, struct CtdlMessage *msg) {
        FILE *tmp;
        char buf[1024];
        char *ptr;
@@ -106,7 +106,7 @@ void imap_fetch_rfc822(int msgnum, char *whichfmt) {
         * Load the message into a temp file for translation and measurement
         */ 
        CtdlRedirectOutput(tmp, -1);
-       CtdlOutputMsg(msgnum, MT_RFC822, 0, 0, 1);
+       CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822, 0, 0, 1);
        CtdlRedirectOutput(NULL, -1);
 
        /*
@@ -213,7 +213,8 @@ void imap_load_part(char *name, char *filename, char *partnum, char *disp,
 /*
  * Implements the ENVELOPE fetch item
  * 
- * FIXME ... we have to actually do something useful here.
+ * FIXME ... we only output some of the fields right now.  Definitely need
+ *           to do all of them.  Accurately, too.
  *
  * Note that the imap_strout() function can cleverly output NULL fields as NIL,
  * so we don't have to check for that condition like we do elsewhere.
@@ -325,7 +326,7 @@ void imap_fetch_body(long msgnum, char *item, int is_peek,
 
        if (!strcmp(section, "")) {             /* the whole thing */
                CtdlRedirectOutput(tmp, -1);
-               CtdlOutputMsg(msgnum, MT_RFC822, 0, 0, 1);
+               CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822, 0, 0, 1);
                CtdlRedirectOutput(NULL, -1);
        }
 
@@ -335,7 +336,7 @@ void imap_fetch_body(long msgnum, char *item, int is_peek,
         */
        else if (!strncasecmp(section, "HEADER", 6)) {
                CtdlRedirectOutput(tmp, -1);
-               CtdlOutputMsg(msgnum, MT_RFC822, 1, 0, 1);
+               CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822, 1, 0, 1);
                CtdlRedirectOutput(NULL, -1);
                imap_strip_headers(tmp);
        }
@@ -390,6 +391,57 @@ void imap_fetch_body(long msgnum, char *item, int is_peek,
 }
 
 
+/*
+ * Spew the BODYSTRUCTURE data for a message.  (Do you need a silencer if
+ * you're going to shoot a MIME?  Do you need a reason to shoot Mark Crispin?
+ * No, and no.)
+ *
+ * FIXME finish the implementation
+ */
+void imap_fetch_bodystructure (long msgnum, char *item,
+               struct CtdlMessage *msg) {
+       FILE *tmp;
+       char buf[1024];
+       long lines = 0L;
+       long bytes = 0L;
+
+
+       /* For non-RFC822 (ordinary Citadel) messages, this is short and
+        * sweet...
+        */
+       if (msg->cm_format_type != FMT_RFC822) {
+
+               /* *sigh* We have to RFC822-format the message just to be able
+                * to measure it.
+                */
+               tmp = tmpfile();
+               if (tmp == NULL) return;
+               CtdlRedirectOutput(tmp, -1);
+               CtdlOutputPreLoadedMsg(msg, msgnum, MT_RFC822, 0, 0, 1);
+               CtdlRedirectOutput(NULL, -1);
+
+               rewind(tmp);
+               while (fgets(buf, sizeof buf, tmp) != NULL) ++lines;
+               bytes = ftell(tmp);
+               fclose(tmp);
+
+               cprintf("BODYSTRUCTURE (\"TEXT\" \"PLAIN\" "
+                       "(\"CHARSET\" \"US-ASCII\") NIL NIL "
+                       "\"7BIT\" %ld %ld) ", bytes, lines);
+
+               return;
+       }
+
+       /* For messages already stored in RFC822 format, we have to parse. */
+       /* FIXME do this! */
+
+
+}
+
+
+
+
+
 
 /*
  * imap_do_fetch() calls imap_do_fetch_msg() to output the deta of an
@@ -412,7 +464,8 @@ void imap_do_fetch_msg(int seq, struct CtdlMessage *msg,
                                        1, msg);
                }
                else if (!strcasecmp(itemlist[i], "BODYSTRUCTURE")) {
-                       /* FIXME do something here */
+                       imap_fetch_bodystructure(IMAP->msgids[seq-1],
+                                       itemlist[i], msg);
                }
                else if (!strcasecmp(itemlist[i], "ENVELOPE")) {
                        imap_fetch_envelope(IMAP->msgids[seq-1], msg);
@@ -424,16 +477,16 @@ void imap_do_fetch_msg(int seq, struct CtdlMessage *msg,
                        imap_fetch_internaldate(msg);
                }
                else if (!strcasecmp(itemlist[i], "RFC822")) {
-                       imap_fetch_rfc822(IMAP->msgids[seq-1], itemlist[i]);
+                       imap_fetch_rfc822(IMAP->msgids[seq-1], itemlist[i], msg);
                }
                else if (!strcasecmp(itemlist[i], "RFC822.HEADER")) {
-                       imap_fetch_rfc822(IMAP->msgids[seq-1], itemlist[i]);
+                       imap_fetch_rfc822(IMAP->msgids[seq-1], itemlist[i], msg);
                }
                else if (!strcasecmp(itemlist[i], "RFC822.SIZE")) {
-                       imap_fetch_rfc822(IMAP->msgids[seq-1], itemlist[i]);
+                       imap_fetch_rfc822(IMAP->msgids[seq-1], itemlist[i], msg);
                }
                else if (!strcasecmp(itemlist[i], "RFC822.TEXT")) {
-                       imap_fetch_rfc822(IMAP->msgids[seq-1], itemlist[i]);
+                       imap_fetch_rfc822(IMAP->msgids[seq-1], itemlist[i], msg);
                }
                else if (!strcasecmp(itemlist[i], "UID")) {
                        imap_fetch_uid(seq);
index b283b749e4bc8152bb0dfb137a571fa696bcd41e..72dc41328c733f2603924dfbccf1edd8efcc1757 100644 (file)
@@ -785,31 +785,13 @@ int CtdlOutputMsg(long msg_num,           /* message number (local) to fetch */
                int do_proto,           /* do Citadel protocol responses? */
                int crlf                /* Use CRLF newlines instead of LF? */
 ) {
-       int i, k;
-       char buf[1024];
-       CIT_UBYTE ch;
-       char allkeys[256];
-       char display_name[256];
        struct CtdlMessage *TheMessage;
-       char *mptr;
-       char *nl;       /* newline string */
-
-       /* buffers needed for RFC822 translation */
-       char suser[256];
-       char luser[256];
-       char fuser[256];
-       char snode[256];
-       char lnode[256];
-       char mid[256];
-       char datestamp[256];
-       /*                                       */
+       int retcode;
 
        lprintf(7, "CtdlOutputMsg() msgnum=%ld, mode=%d\n", 
                msg_num, mode);
 
        TheMessage = NULL;
-       sprintf(mid, "%ld", msg_num);
-       nl = (crlf ? "\r\n" : "\n");
 
        if ((!(CC->logged_in)) && (!(CC->internal_pgm))) {
                if (do_proto) cprintf("%d Not logged in.\n",
@@ -839,6 +821,47 @@ int CtdlOutputMsg(long msg_num,            /* message number (local) to fetch */
                        ERROR, msg_num);
                return(om_no_such_msg);
        }
+       
+       retcode = CtdlOutputPreLoadedMsg(
+                       TheMessage, msg_num, mode,
+                       headers_only, do_proto, crlf);
+
+       CtdlFreeMessage(TheMessage);
+       return(retcode);
+}
+
+
+/*
+ * Get a message off disk.  (returns om_* values found in msgbase.h)
+ * 
+ */
+int CtdlOutputPreLoadedMsg(struct CtdlMessage *TheMessage,
+               long msg_num,
+               int mode,               /* how would you like that message? */
+               int headers_only,       /* eschew the message body? */
+               int do_proto,           /* do Citadel protocol responses? */
+               int crlf                /* Use CRLF newlines instead of LF? */
+) {
+       int i, k;
+       char buf[1024];
+       CIT_UBYTE ch;
+       char allkeys[256];
+       char display_name[256];
+       char *mptr;
+       char *nl;       /* newline string */
+
+       /* buffers needed for RFC822 translation */
+       char suser[256];
+       char luser[256];
+       char fuser[256];
+       char snode[256];
+       char lnode[256];
+       char mid[256];
+       char datestamp[256];
+       /*                                       */
+
+       sprintf(mid, "%ld", msg_num);
+       nl = (crlf ? "\r\n" : "\n");
 
        /* Are we downloading a MIME component? */
        if (mode == MT_DOWNLOAD) {
@@ -1097,7 +1120,6 @@ int CtdlOutputMsg(long msg_num,           /* message number (local) to fetch */
 
        /* now we're done */
        if (do_proto) cprintf("000\n");
-       CtdlFreeMessage(TheMessage);
        return(om_ok);
 }
 
index a0a17eb278b7b6861ce2f11a34ecd251cd876214..50db62bfa5e466ec9c286a3ab6629351ca3d9a5a 100644 (file)
@@ -94,3 +94,9 @@ int CtdlOutputMsg(long msg_num,               /* message number (local) to fetch */
                int headers_only,       /* eschew the message body? */
                int do_proto,           /* do Citadel protocol responses? */
                int crlf);
+int CtdlOutputPreLoadedMsg(struct CtdlMessage *,
+               long,
+               int mode,               /* how would you like that message? */
+               int headers_only,       /* eschew the message body? */
+               int do_proto,           /* do Citadel protocol responses? */
+               int crlf);