$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)
Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
* Initial CVS import
+
/* 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");
}
/*
- * 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;
}
}
+
+
+/*
+ * 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
*/
/* $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);
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, '|')