* Added some more functionality to the string tokenizer
authorArt Cancro <ajc@citadel.org>
Sat, 22 Jan 2000 05:13:56 +0000 (05:13 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 22 Jan 2000 05:13:56 +0000 (05:13 +0000)
citadel/ChangeLog
citadel/serv_smtp.c
citadel/tools.c
citadel/tools.h

index 2561a507b4b4af30ef0ae5fc893c25f9427c27a3..cf3cc72a493f88160a261680f89f5a82f9cf75de 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 1.449  2000/01/22 05:13:56  ajc
+* Added some more functionality to the string tokenizer
+
 Revision 1.448  2000/01/17 20:57:43  ajc
 * CR to CRLF hacks (lose, lose, lose)
 
@@ -1572,3 +1575,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
+
index 60dd06d4f67da712b752f9b8c2a2b639fe696dde..517e5d040f6c611b8ea5642ee3fcb3ad62b0b5e1 100644 (file)
@@ -667,12 +667,78 @@ void smtp_command_loop(void) {
 /*               SMTP CLIENT (OUTBOUND PROCESSING) STUFF                     */
 /*****************************************************************************/
 
+
+
+/*
+ * smtp_do_procmsg()
+ *
+ * Called by smtp_do_queue() to handle an individual message.
+ */
+void smtp_do_procmsg(long msgnum) {
+       struct CtdlMessage *msg;
+       char *instr;
+       int i;
+       int lines;
+       char buf[256];
+       char key[256];
+       long msgid = (-1);
+
+       msg = CtdlFetchMessage(msgnum);
+       if (msg == NULL) {
+               lprintf(3, "SMTP: tried %ld but no such message!\n", msgnum);
+               return;
+       }
+
+       instr = msg->cm_fields['M'];
+
+       /* Strip out the headers amd any other non-instruction line */
+       lines = num_tokens(instr, '\n');
+       for (i=0; i<lines; ++i) {
+               extract_token(buf, instr, '\n');
+               if (num_tokens(buf, '|') < 2) {
+                       lprintf(9, "removing <%s>\n", buf);
+                       remove_token(instr, i, '|');
+                       --lines;
+                       --i;
+               }
+       }
+
+       /* Learn the message ID */
+       lines = num_tokens(instr, '\n');
+       for (i=0; i<lines; ++i) {
+               extract_token(buf, instr, '\n');
+               extract(key, buf, 0);
+               if (!strcasecmp(key, "msgid")) {
+                       msgid = extract_long(buf, 1);
+               }
+       }
+
+
+/****** FIX    this is nowhere near done   *******/
+
+
+
+
+       CtdlFreeMessage(msg);
+}
+
+
+
 /*
  * smtp_do_queue()
  * 
  * Run through the queue sending out messages.
  */
 void smtp_do_queue(void) {
+       lprintf(5, "SMTP: processing outbound queue\n");
+
+       if (getroom(&CC->quickroom, SMTP_SPOOLOUT_ROOM) != 0) {
+               lprintf(3, "Cannot find room <%s>\n", SMTP_SPOOLOUT_ROOM);
+               return;
+       }
+       CtdlForEachMessage(MSGS_ALL, 0L, SPOOLMIME, NULL, smtp_do_procmsg);
+
+       lprintf(5, "SMTP: queue run completed\n");
 }
 
 
index 052122e6607d1461ff14bd5e616fbe7bb5701646..d8652c3b6728e5a4ba1fa986a353b0f474348280 100644 (file)
@@ -30,22 +30,22 @@ char *safestrncpy(char *dest, const char *src, size_t n)
 
 
 /*
- * num_parms()  -  discover number of parameters...
+ * num_tokens()  -  discover number of parameters/tokens in a string
  */
-int num_parms(char *source)
-{
+int num_tokens(char *source, char tok) {
        int a;
        int count = 1;
 
-       for (a=0; a<strlen(source); ++a) 
-               if (source[a]=='|') ++count;
+       for (a=0; a<strlen(source); ++a) {
+               if (source[a]==tok) ++count;
+       }
        return(count);
 }
 
 /*
- * extract()  -  a smarter string tokenizer
+ * extract_token()  -  a smarter string tokenizer
  */
-void extract_token(char *dest, char *source, int parmnum, char separator)
+void extract_token(char *dest, char *source, int parmnum, char separator) 
 {
        int i;
        int len;
@@ -70,6 +70,51 @@ void extract_token(char *dest, char *source, int parmnum, char separator)
        }
 }
 
+
+
+/*
+ * remove_token()  -  a tokenizer that kills, maims, and destroys
+ */
+void remove_token(char *source, int parmnum, char separator)
+{
+       int i;
+       int len;
+       int curr_parm;
+       int start, end;
+
+       len = 0;
+       curr_parm = 0;
+       start = (-1);
+       end = (-1);
+
+       if (strlen(source)==0) {
+               return;
+               }
+
+       for (i=0; i<strlen(source); ++i) {
+               if ( (start < 0) && (curr_parm == parmnum) ) {
+                       start = i;
+               }
+
+               if ( (end < 0) && (curr_parm == (parmnum+1)) ) {
+                       end = i;
+               }
+
+               if (source[i]==separator) {
+                       ++curr_parm;
+               }
+       }
+
+       if (end < 0) end = strlen(source);
+
+       printf("%d .. %d\n", start, end);
+
+       strcpy(&source[start], &source[end]);
+}
+
+
+
+
 /*
  * extract_int()  -  extract an int parm w/o supplying a buffer
  */
index 2286cd869b846102956915be2aa7bd78dd36ae93..a40831c2aa66545be7b75ced1ed483525d4e7547 100644 (file)
@@ -1,6 +1,6 @@
 /* $Id$ */
 char *safestrncpy(char *dest, const char *src, size_t n);
-int num_parms (char *source);
+int num_tokens (char *source, char tok);
 void extract_token(char *dest, char *source, int parmnum, char separator);
 int extract_int (char *source, int parmnum);
 long int extract_long (char *source, long int parmnum);
@@ -9,6 +9,7 @@ void decode_base64(char *dest, char *source);
 void striplt(char *);
 int haschar(char *st, int ch);
 int collapsed_strcmp(char *s1, char *s2);
-
+void remove_token(char *source, int parmnum, char separator);
 
 #define extract(dest,source,parmnum)   extract_token(dest,source,parmnum,'|')
+#define num_parms(source)              num_tokens(source, '|')