Mailing list header changes (fuck you Google)
[citadel.git] / ctdlsh / mailq.c
1 /*
2  * (c) 1987-2017 by Art Cancro and citadel.org
3  * This program is open source software, released under the terms of the GNU General Public License v3.
4  * It runs really well on the Linux operating system.
5  * We love open source software but reject Richard Stallman's linguistic fascism.
6  */
7
8 #include "ctdlsh.h"
9
10
11 void mailq_show_this_queue_entry(StrBuf * MsgText)
12 {
13         const char *Pos = NULL;
14         StrBuf *Line = NewStrBuf();
15         int sip = 0;
16
17         do {
18                 sip = StrBufSipLine(Line, MsgText, &Pos);
19
20                 if (!strncasecmp(ChrPtr(Line), HKEY("msgid|"))) {
21                         printf("Message %ld:\n", atol(ChrPtr(Line) + 6));
22                 } else if (!strncasecmp(ChrPtr(Line), HKEY("submitted|"))) {
23                         time_t submitted = atol(ChrPtr(Line) + 10);
24                         printf("Originally submitted: %s", asctime(localtime(&submitted)));
25                 } else if (!strncasecmp(ChrPtr(Line), HKEY("attempted|"))) {
26                         time_t attempted = atol(ChrPtr(Line) + 10);
27                         printf("Last delivery attempt: %s", asctime(localtime(&attempted)));
28                 } else if (!strncasecmp(ChrPtr(Line), HKEY("bounceto|"))) {
29                         printf("Sender: %s\n", ChrPtr(Line) + 9);
30                 } else if (!strncasecmp(ChrPtr(Line), HKEY("remote|"))) {
31                         printf("Recipient: %s\n", ChrPtr(Line) + 7);
32                 }
33         } while (sip);
34
35         FreeStrBuf(&Line);
36         printf("\n");
37 }
38
39
40 int cmd_mailq(int server_socket, char *cmdbuf)
41 {
42         char buf[1024];
43         long *msgs = NULL;
44         int num_msgs = 0;
45         int num_alloc = 0;
46         int i;
47         StrBuf *MsgText;
48
49         sock_puts(server_socket, "GOTO __CitadelSMTPspoolout__");
50         sock_getln(server_socket, buf, sizeof buf);
51         if (buf[0] != '2') {
52                 printf("%s\n", &buf[4]);
53                 return (cmdret_error);
54         }
55
56         sock_puts(server_socket, "MSGS ALL");
57         sock_getln(server_socket, buf, sizeof buf);
58         if (buf[0] != '1') {
59                 printf("%s\n", &buf[4]);
60                 return (cmdret_error);
61         }
62
63         MsgText = NewStrBuf();
64         while (sock_getln(server_socket, buf, sizeof buf), strcmp(buf, "000")) {
65
66                 if (num_alloc == 0) {
67                         num_alloc = 100;
68                         msgs = malloc(num_alloc * sizeof(long));
69                 } else if (num_msgs >= num_alloc) {
70                         num_alloc *= 2;
71                         msgs = realloc(msgs, num_alloc * sizeof(long));
72                 }
73
74                 msgs[num_msgs++] = atol(buf);
75         }
76
77         for (i = 0; i < num_msgs; ++i) {
78                 sock_printf(server_socket, "MSG2 %ld\n", msgs[i]);
79                 sock_getln(server_socket, buf, sizeof buf);
80                 if (buf[0] == '1') {
81                         FlushStrBuf(MsgText);
82                         while (sock_getln(server_socket, buf, sizeof buf), strcmp(buf, "000")) {
83                                 StrBufAppendPrintf(MsgText, "%s\n", buf);
84                         }
85                         if (bmstrcasestr((char *) ChrPtr(MsgText), "\nContent-type: application/x-citadel-delivery-list") != NULL) {
86                                 mailq_show_this_queue_entry(MsgText);
87                         }
88                 }
89         }
90
91         if (msgs != NULL) {
92                 free(msgs);
93         }
94         FreeStrBuf(&MsgText);
95         return (cmdret_ok);
96 }