New ctdlsh command "mailq" to show the outbound SMTP queue
authorArt Cancro <ajc@citadel.org>
Thu, 23 Mar 2017 20:25:08 +0000 (16:25 -0400)
committerArt Cancro <ajc@citadel.org>
Thu, 23 Mar 2017 20:25:08 +0000 (16:25 -0400)
ctdlsh/Makefile
ctdlsh/ctdlsh.h
ctdlsh/mailq.c [new file with mode: 0644]
ctdlsh/main.c

index f8ec41b..1a9963e 100644 (file)
@@ -4,11 +4,11 @@
 # config.mk is generated by ./configure
 include config.mk
 
-OBJS := datetime.o export.o main.o passwd.o shutdown.o sockets.o who.o config.o
+OBJS := datetime.o export.o main.o passwd.o shutdown.o sockets.o who.o config.o mailq.o
 
 # link
 ctdlsh: $(OBJS) config.mk
-       gcc $(OBJS) $(LDFLAGS) -lreadline -o ctdlsh
+       gcc $(OBJS) $(LDFLAGS) -lreadline -lcitadel -o ctdlsh
 
 # pull in dependency info for *existing* .o files
 -include $(OBJS:.o=.d)
index 14103fa..07ea135 100644 (file)
@@ -22,6 +22,7 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <readline/readline.h>
+#include <libcitadel.h>
 
 /*
  * Set to the location of Citadel
@@ -47,3 +48,4 @@ int cmd_shutdown(int, char *);
 int cmd_who(int, char *);
 int cmd_export(int, char *);
 int cmd_config(int, char *);
+int cmd_mailq(int, char *);
diff --git a/ctdlsh/mailq.c b/ctdlsh/mailq.c
new file mode 100644 (file)
index 0000000..f897841
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * (c) 1987-2017 by Art Cancro and citadel.org
+ * This program is open source software, released under the terms of the GNU General Public License v3.
+ * It runs really well on the Linux operating system.
+ * We love open source software but reject Richard Stallman's linguistic fascism.
+ */
+
+#include "ctdlsh.h"
+
+
+void mailq_show_this_queue_entry(StrBuf *MsgText) {
+        const char *Pos = NULL;
+       StrBuf *Line = NewStrBuf();
+       int sip = 0;
+
+        do  {
+               sip = StrBufSipLine(Line, MsgText, &Pos);
+
+               if (!strncasecmp(ChrPtr(Line), HKEY("msgid|"))) {
+                       printf("Message %ld:\n", atol(ChrPtr(Line)+6));
+               }
+               else if (!strncasecmp(ChrPtr(Line), HKEY("submitted|"))) {
+                       time_t submitted =  atol(ChrPtr(Line)+10);
+                       printf("Originally submitted: %s", asctime(localtime(&submitted)));
+               }
+               else if (!strncasecmp(ChrPtr(Line), HKEY("attempted|"))) {
+                       time_t attempted =  atol(ChrPtr(Line)+10);
+                       printf("Last delivery attempt: %s", asctime(localtime(&attempted)));
+               }
+               else if (!strncasecmp(ChrPtr(Line), HKEY("bounceto|"))) {
+                       printf("Sender: %s\n", ChrPtr(Line)+10);
+               }
+               else if (!strncasecmp(ChrPtr(Line), HKEY("remote|"))) {
+                       printf("Recipient: %s\n", ChrPtr(Line)+7);
+               }
+       } while(sip);
+
+       FreeStrBuf(&Line);
+       printf("\n");
+}
+
+
+int cmd_mailq(int server_socket, char *cmdbuf) {
+       char buf[1024];
+       long *msgs;
+       int num_msgs = 0;
+       int num_alloc = 0;
+       int i;
+       StrBuf *MsgText;
+
+        sock_puts(server_socket, "GOTO __CitadelSMTPspoolout__");
+        sock_getln(server_socket, buf, sizeof buf);
+       if (buf[0] != '2') {
+               printf("%s\n", &buf[4]);
+               return(cmdret_error);
+       }
+
+        sock_puts(server_socket, "MSGS ALL");
+        sock_getln(server_socket, buf, sizeof buf);
+       if (buf[0] != '1') {
+               printf("%s\n", &buf[4]);
+               return(cmdret_error);
+       }
+
+       MsgText = NewStrBuf();
+        while (sock_getln(server_socket, buf, sizeof buf), strcmp(buf, "000")) {
+
+               if (num_alloc == 0) {
+                       num_alloc = 100;
+                       msgs = malloc(num_alloc * sizeof(long));
+               }
+               else if (num_msgs >= num_alloc) {
+                       num_alloc *= 2;
+                       msgs = realloc(msgs, num_alloc * sizeof(long));
+               }
+
+               msgs[num_msgs++] = atol(buf);
+       }
+
+       for (i=0; i<num_msgs; ++i) {
+               sock_printf(server_socket, "MSG2 %ld\n", msgs[i]);
+               sock_getln(server_socket, buf, sizeof buf);
+               if (buf[0] == '1') {
+                       FlushStrBuf(MsgText);
+                       while (sock_getln(server_socket, buf, sizeof buf), strcmp(buf, "000")) {
+                               StrBufAppendPrintf(MsgText, "%s\n", buf);
+                       }
+                       if (bmstrcasestr((char *)ChrPtr(MsgText), "\nContent-type: application/x-citadel-delivery-list") != NULL) {
+                               mailq_show_this_queue_entry(MsgText);
+                       }
+               }
+       }
+
+       free(msgs);
+       FreeStrBuf(&MsgText);
+        return(cmdret_ok);
+}
index 80b2fd0..b159c9c 100644 (file)
@@ -32,6 +32,7 @@ COMMAND commands[] = {
        {       "who",          cmd_who,        "Display a list of online users"        },
        {       "exit",         cmd_quit,       "Quit using ctdlsh"                     },
        {       "quit",         cmd_quit,       "Quit using ctdlsh"                     },
+       {       "mailq",        cmd_mailq,      "Show the outbound email queue"         },
        {       NULL,           NULL,           NULL                                    }
 };
 
@@ -72,6 +73,7 @@ char *command_generator(const char *text, int state) {
 char **ctdlsh_completion(const char *text, int start, int end) {
        char **matches = (char **) NULL;
 
+       rl_completer_word_break_characters = " ";
        if (start == 0) {
                matches = rl_completion_matches(text, command_generator);
        }