* Merged Thierry's CSS changes
[citadel.git] / webcit / smtpqueue.c
1 /* 
2  * $Id: $
3  */
4 /**
5  * \defgroup SMTPqueue Display the outbound SMTP queue
6  * \ingroup CitadelConfig
7  */
8 /*@{*/
9 #include "webcit.h"
10
11 /**
12  * \brief display one message in the queue
13  */
14 void display_queue_msg(long msgnum)
15 {
16         char buf[1024];
17         char keyword[32];
18         int in_body = 0;
19         int is_delivery_list = 0;
20         time_t submitted = 0;
21         time_t attempted = 0;
22         time_t last_attempt = 0;
23         int number_of_attempts = 0;
24         char sender[256];
25         char recipients[65536];
26         char thisrecp[256];
27         char thisdsn[256];
28         long msgid = 0;
29
30         strcpy(sender, "");
31         strcpy(recipients, "");
32
33         serv_printf("MSG2 %ld", msgnum);
34         serv_getln(buf, sizeof buf);
35         if (buf[0] != '1') return;
36
37         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
38
39                 if (strlen(buf) > 0) {
40                         if (buf[strlen(buf)-1] == 13) {
41                                 buf[strlen(buf)-1] = 0;
42                         }
43                 }
44
45                 if ( (strlen(buf) == 0) && (in_body == 0) ) {
46                         in_body = 1;
47                 }
48
49                 if ( (!in_body)
50                    && (!strncasecmp(buf, "Content-type: application/x-citadel-delivery-list", 49))
51                 ) {
52                         is_delivery_list = 1;
53                 }
54
55                 if ( (in_body) && (!is_delivery_list) ) {
56                         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
57                                 /* Not a delivery list; flush and return quietly. */
58                         }
59                         return;
60                 }
61
62                 if ( (in_body) && (is_delivery_list) ) {
63                         extract_token(keyword, buf, 0, '|', sizeof keyword);
64
65                         if (!strcasecmp(keyword, "msgid")) {
66                                 msgid = extract_long(buf, 1);
67                         }
68
69                         if (!strcasecmp(keyword, "submitted")) {
70                                 submitted = extract_long(buf, 1);
71                         }
72
73                         if (!strcasecmp(keyword, "attempted")) {
74                                 attempted = extract_long(buf, 1);
75                                 ++number_of_attempts;
76                                 if (attempted > last_attempt) {
77                                         last_attempt = attempted;
78                                 }
79                         }
80
81                         if (!strcasecmp(keyword, "bounceto")) {
82                                 extract_token(sender, buf, 1, '|', sizeof sender);
83
84                                 /* Strip off local hostname if it's our own */
85                                 char *atsign;
86                                 atsign = strchr(sender, '@');
87                                 if (atsign != NULL) {
88                                         ++atsign;
89                                         if (!strcasecmp(atsign, serv_info.serv_nodename)) {
90                                                 --atsign;
91                                                 *atsign = 0;
92                                         }
93                                 }
94                         }
95
96                         if (!strcasecmp(keyword, "remote")) {
97                                 extract_token(thisrecp, buf, 1, '|', sizeof thisrecp);
98                                 extract_token(thisdsn, buf, 3, '|', sizeof thisdsn);
99
100                                 if (strlen(recipients) + strlen(thisrecp) + strlen(thisdsn) + 100
101                                    < sizeof recipients) {
102                                         if (strlen(recipients) > 0) {
103                                                 strcat(recipients, "<br />");
104                                         }
105                                         stresc(&recipients[strlen(recipients)], thisrecp, 1, 1);
106                                         strcat(recipients, "<br />&nbsp;&nbsp;<i>");
107                                         stresc(&recipients[strlen(recipients)], thisdsn, 1, 1);
108                                         strcat(recipients, "</i>");
109                                 }
110
111                         }
112
113                 }
114
115         }
116
117         wprintf("<tr><td>");
118         wprintf("%ld<br />", msgnum);
119         wprintf(" <a href=\"javascript:DeleteQueueMsg(%ld,%ld);\">%s</a>", 
120                 msgnum, msgid, _("(Delete)")
121         );
122
123         wprintf("</td><td>");
124         if (submitted > 0) {
125                 fmt_date(buf, submitted, 1);
126                 wprintf("%s", buf);
127         }
128         else {
129                 wprintf("&nbsp;");
130         }
131
132         wprintf("</td><td>");
133         if (last_attempt > 0) {
134                 fmt_date(buf, last_attempt, 1);
135                 wprintf("%s", buf);
136         }
137         else {
138                 wprintf("&nbsp;");
139         }
140
141         wprintf("</td><td>");
142         escputs(sender);
143
144         wprintf("</td><td>");
145         wprintf("%s", recipients);
146         wprintf("</td></tr>\n");
147
148 }
149
150
151 void display_smtpqueue_inner_div(void) {
152         int i;
153         int num_msgs;
154
155         /* Check to see if we can go to the __CitadelSMTPspoolout__ room.
156          * If not, we don't have access to the queue.
157          */
158         gotoroom("__CitadelSMTPspoolout__");
159         if (!strcasecmp(WC->wc_roomname, "__CitadelSMTPspoolout__")) {
160
161                 num_msgs = load_msg_ptrs("MSGS ALL", 0);
162                 if (num_msgs > 0) {
163                         wprintf("<table class=\"mailbox_summary\" rules=rows "
164                                 "cellpadding=2 style=\"width:100%%;-moz-user-select:none;\">"
165                         );
166
167                         wprintf("<tr><td><b><i>");
168                         wprintf(_("Message ID"));
169                         wprintf("</i></b></td><td><b><i>");
170                         wprintf(_("Date/time submitted"));
171                         wprintf("</i></b></td><td><b><i>");
172                         wprintf(_("Last attempt"));
173                         wprintf("</i></b></td><td><b><i>");
174                         wprintf(_("Sender"));
175                         wprintf("</i></b></td><td><b><i>");
176                         wprintf(_("Recipients"));
177                         wprintf("</i></b></td></tr>\n");
178
179                         for (i=0; i<num_msgs; ++i) {
180                                 display_queue_msg(WC->msgarr[i]);
181                         }
182
183                         wprintf("</table>");
184
185                 }
186                 else {
187                         wprintf("<br /><br /><div align=\"center\">");
188                         wprintf(_("The queue is empty."));
189                         wprintf("</div><br /><br />");
190                 }
191         }
192         else {
193                 wprintf("<br /><br /><div align=\"center\">");
194                 wprintf(_("You do not have permission to view this resource."));
195                 wprintf("</div><br /><br />");
196         }
197
198 }
199
200 /**
201  * \brief display the outbound SMTP queue
202  */
203 void display_smtpqueue(void)
204 {
205         output_headers(1, 1, 2, 0, 0, 0);
206
207         wprintf("<script type=\"text/javascript\">                              \n"
208                 "function RefreshQueueDisplay() {                               \n"
209                 "       new Ajax.Updater('smtpqueue_inner_div',                 \n"
210                 "       'display_smtpqueue_inner_div', { method: 'get',         \n"
211                 "               parameters: Math.random() } );                  \n"
212                 "}                                                              \n"
213                 "                                                               \n"
214                 "function DeleteQueueMsg(msgnum1, msgnum2) {                                    \n"
215                 "       new Ajax.Request(                                                       \n"
216                 "               'ajax_servcmd', {                                               \n"
217                 "                       method: 'post',                                         \n"
218                 "                       parameters: 'g_cmd=DELE ' + msgnum1 + ',' + msgnum2,    \n"
219                 "                       onComplete: RefreshQueueDisplay()                       \n"
220                 "               }                                                               \n"
221                 "       );                                                                      \n"
222                 "}                                                                              \n"
223                 "                                                               \n"
224                 "</script>                                                      \n"
225         );
226
227         wprintf("<div id=\"banner\">\n");
228         wprintf("<TABLE class=\"smtpqueue_banner\"><TR><TD>");
229         wprintf("<SPAN CLASS=\"titlebar\">");
230         wprintf(_("View the outbound SMTP queue"));
231         wprintf("</SPAN>\n");
232         wprintf("</TD></TR></TABLE>\n");
233         wprintf("</div>\n<div id=\"content\">\n");
234
235         wprintf("<div class=\"fix_scrollbar_bug\">"
236                 "<table class=\"smtpqueue_background\">"
237                 "<tr><td valign=top>\n");
238
239         wprintf("<div id=\"smtpqueue_inner_div\">");
240
241         display_smtpqueue_inner_div();
242
243         wprintf("</div>"
244                 "<div align=\"center\">"
245                 "<a href=\"javascript:RefreshQueueDisplay();\">%s</a>"
246                 "</div>"
247                 "</td></tr></table></div>\n", _("Refresh this page")
248         );
249         wDumpContent(1);
250
251 }
252
253
254
255
256 /*@}*/