]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/smtp/serv_smtpclient.c
Temporarily adding dump of badmail to smtpclient
[citadel.git] / citadel / modules / smtp / serv_smtpclient.c
index 9782d3e42ebad236495acc3243a2cedaf7257abd..8b84b12dd1ee2b70521a7f63ccf3979158f0d97b 100644 (file)
@@ -20,9 +20,9 @@
  * The VRFY and EXPN commands have been removed from this implementation
  * because nobody uses these commands anymore, except for spammers.
  *
- * Copyright (c) 1998-2009 by the citadel.org team
+ * Copyright (c) 1998-2011 by the citadel.org team
  *
- *  This program is free software; you can redistribute it and/or modify
+ *  This program is open source software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 3 of the License, or
  *  (at your option) any later version.
@@ -183,7 +183,15 @@ void smtp_try(const char *key, const char *addr, int *status,
                                scan_done = 1;
                        }
                } while (scan_done == 0);
-               if (IsEmptyStr(mailfrom)) strcpy(mailfrom, "someone@somewhere.org");
+               if (IsEmptyStr(mailfrom)) {
+                       char badmail_filename[128];
+                       snprintf(badmail_filename, sizeof badmail_filename, "/tmp/badmail.%d.%ld",
+                               getpid, time(NULL)
+                       );
+                       FILE *badmail_fp = fopen(badmail_filename, "w");
+                       fwrite(msgtext, msg_size, 1, badmail_fp);
+                       fclose(badmail_fp);
+               }
                stripallbut(mailfrom, '<', '>');
                envelope_from = mailfrom;
        }
@@ -937,30 +945,23 @@ void cmd_smtp(char *argbuf) {
  * 
  * Run through the queue sending out messages.
  */
-void *smtp_queue_thread(void *arg) {
+void smtp_do_queue(void) {
+       static int is_running = 0;
        int num_processed = 0;
-       struct CitContext smtp_queue_CC;
 
-       CtdlFillSystemContext(&smtp_queue_CC, "SMTP Send");
-       citthread_setspecific(MyConKey, (void *)&smtp_queue_CC);
-       syslog(LOG_DEBUG, "smtp_queue_thread() initializing\n");
+       if (is_running) return;         /* Concurrency check - only one can run */
+       is_running = 1;
 
-       while (!CtdlThreadCheckStop()) {
-               
-               syslog(LOG_INFO, "SMTP client: processing outbound queue\n");
+       syslog(LOG_INFO, "SMTP client: processing outbound queue\n");
 
-               if (CtdlGetRoom(&CC->room, SMTP_SPOOLOUT_ROOM) != 0) {
-                       syslog(LOG_ERR, "Cannot find room <%s>\n", SMTP_SPOOLOUT_ROOM);
-               }
-               else {
-                       num_processed = CtdlForEachMessage(MSGS_ALL, 0L, NULL, SPOOLMIME, NULL, smtp_do_procmsg, NULL);
-               }
-               syslog(LOG_INFO, "SMTP client: queue run completed; %d messages processed\n", num_processed);
-               CtdlThreadSleep(60);
+       if (CtdlGetRoom(&CC->room, SMTP_SPOOLOUT_ROOM) != 0) {
+               syslog(LOG_ERR, "Cannot find room <%s>\n", SMTP_SPOOLOUT_ROOM);
        }
-
-       CtdlClearSystemContext();
-       return(NULL);
+       else {
+               num_processed = CtdlForEachMessage(MSGS_ALL, 0L, NULL, SPOOLMIME, NULL, smtp_do_procmsg, NULL);
+       }
+       syslog(LOG_INFO, "SMTP client: queue run completed; %d messages processed\n", num_processed);
+       is_running = 0;
 }
 
 
@@ -995,7 +996,7 @@ CTDL_MODULE_INIT(smtp_client)
        if (!threading)
        {
                smtp_init_spoolout();
-               CtdlThreadCreate("SMTP Send", CTDLTHREAD_BIGSTACK, smtp_queue_thread, NULL);
+               CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER);
                CtdlRegisterProtoHook(cmd_smtp, "SMTP", "SMTP utility commands");
        }