File: smtpqueue.c

package info (click to toggle)
webcit 7.37-dfsg-7
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 6,972 kB
  • ctags: 2,344
  • sloc: ansic: 23,301; sh: 3,618; makefile: 239
file content (271 lines) | stat: -rw-r--r-- 6,105 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/* 
 * $Id: smtpqueue.c 6383 2008-06-16 02:16:02Z ajc $
 *
 * Display the outbound SMTP queue
 */

#include "webcit.h"

/*
 * display one message in the queue
 */
void display_queue_msg(long msgnum)
{
	char buf[1024];
	char keyword[32];
	int in_body = 0;
	int is_delivery_list = 0;
	time_t submitted = 0;
	time_t attempted = 0;
	time_t last_attempt = 0;
	int number_of_attempts = 0;
	char sender[256];
	char recipients[65536];
	int recipients_len = 0;
	char thisrecp[256];
	char thisdsn[256];
	char thismsg[512];
	int thismsg_len;
	long msgid = 0;
	int len;

	strcpy(sender, "");
	strcpy(recipients, "");
	recipients_len = 0;

	serv_printf("MSG2 %ld", msgnum);
	serv_getln(buf, sizeof buf);
	if (buf[0] != '1') return;

	while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {

		if (!IsEmptyStr(buf)) {
			len = strlen(buf);
			if (buf[len - 1] == 13) {
				buf[len - 1] = 0;
			}
		}

		if ( (IsEmptyStr(buf)) && (in_body == 0) ) {
			in_body = 1;
		}

		if ( (!in_body)
		   && (!strncasecmp(buf, "Content-type: application/x-citadel-delivery-list", 49))
		) {
			is_delivery_list = 1;
		}

		if ( (in_body) && (!is_delivery_list) ) {
			while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
				/* Not a delivery list; flush and return quietly. */
			}
			return;
		}

		if ( (in_body) && (is_delivery_list) ) {
			extract_token(keyword, buf, 0, '|', sizeof keyword);

			if (!strcasecmp(keyword, "msgid")) {
				msgid = extract_long(buf, 1);
			}

			if (!strcasecmp(keyword, "submitted")) {
				submitted = extract_long(buf, 1);
			}

			if (!strcasecmp(keyword, "attempted")) {
				attempted = extract_long(buf, 1);
				++number_of_attempts;
				if (attempted > last_attempt) {
					last_attempt = attempted;
				}
			}

			if (!strcasecmp(keyword, "bounceto")) {
				extract_token(sender, buf, 1, '|', sizeof sender);

				/* Strip off local hostname if it's our own */
				char *atsign;
				atsign = strchr(sender, '@');
				if (atsign != NULL) {
					++atsign;
					if (!strcasecmp(atsign, serv_info.serv_nodename)) {
						--atsign;
						*atsign = 0;
					}
				}
			}

			if (!strcasecmp(keyword, "remote")) {
				thismsg[0] = 0;

				extract_token(thisrecp, buf, 1, '|', sizeof thisrecp);
				extract_token(thisdsn, buf, 3, '|', sizeof thisdsn);

				if (!IsEmptyStr(thisrecp)) {
					stresc(thismsg, sizeof thismsg, thisrecp, 1, 1);
					if (!IsEmptyStr(thisdsn)) {
						strcat(thismsg, "<br />&nbsp;&nbsp;<i>");
						stresc(&thismsg[strlen(thismsg)], sizeof thismsg,
							thisdsn, 1, 1);
						strcat(thismsg, "</i>");
					}
					thismsg_len = strlen(thismsg);

					if ((recipients_len + thismsg_len + 100) < sizeof recipients) {
						if (!IsEmptyStr(recipients)) {
							strcpy(&recipients[recipients_len], "<br />");
							recipients_len += 6;
						}
						strcpy(&recipients[recipients_len], thismsg);
						recipients_len += thismsg_len;
					}
				}

			}

		}

	}

	wprintf("<tr><td>");
	wprintf("%ld<br />", msgnum);
	wprintf(" <a href=\"javascript:DeleteQueueMsg(%ld,%ld);\">%s</a>", 
		msgnum, msgid, _("(Delete)")
	);

	wprintf("</td><td>");
	if (submitted > 0) {
		webcit_fmt_date(buf, submitted, 1);
		wprintf("%s", buf);
	}
	else {
		wprintf("&nbsp;");
	}

	wprintf("</td><td>");
	if (last_attempt > 0) {
		webcit_fmt_date(buf, last_attempt, 1);
		wprintf("%s", buf);
	}
	else {
		wprintf("&nbsp;");
	}

	wprintf("</td><td>");
	escputs(sender);

	wprintf("</td><td>");
	wprintf("%s", recipients);
	wprintf("</td></tr>\n");

}


void display_smtpqueue_inner_div(void) {
	int i;
	int num_msgs;

	/* Check to see if we can go to the __CitadelSMTPspoolout__ room.
	 * If not, we don't have access to the queue.
	 */
	gotoroom("__CitadelSMTPspoolout__");
	if (!strcasecmp(WC->wc_roomname, "__CitadelSMTPspoolout__")) {

		num_msgs = load_msg_ptrs("MSGS ALL", 0);
		if (num_msgs > 0) {
                        wprintf("<table class=\"mailbox_summary\" rules=rows "
                        	"cellpadding=2 style=\"width:100%%;\">"
			);

			wprintf("<tr><td><b><i>");
			wprintf(_("Message ID"));
			wprintf("</i></b></td><td><b><i>");
			wprintf(_("Date/time submitted"));
			wprintf("</i></b></td><td><b><i>");
			wprintf(_("Last attempt"));
			wprintf("</i></b></td><td><b><i>");
			wprintf(_("Sender"));
			wprintf("</i></b></td><td><b><i>");
			wprintf(_("Recipients"));
			wprintf("</i></b></td></tr>\n");

			for (i=0; i<num_msgs; ++i) {
				display_queue_msg(WC->msgarr[i]);
			}

			wprintf("</table>");

		}
		else {
			wprintf("<br /><br /><div align=\"center\">");
			wprintf(_("The queue is empty."));
			wprintf("</div><br /><br />");
		}
	}
	else {
		wprintf("<br /><br /><div align=\"center\">");
		wprintf(_("You do not have permission to view this resource."));
		wprintf("</div><br /><br />");
	}

}

/**
 * \brief display the outbound SMTP queue
 */
void display_smtpqueue(void)
{
	output_headers(1, 1, 2, 0, 0, 0);

	wprintf("<script type=\"text/javascript\">				\n"
		"function RefreshQueueDisplay() {				\n"
		"	new Ajax.Updater('smtpqueue_inner_div', 		\n"
		"	'display_smtpqueue_inner_div', { method: 'get',		\n"
		"		parameters: Math.random() } );			\n"
		"}								\n"
		"								\n"
		"function DeleteQueueMsg(msgnum1, msgnum2) {					\n"
 		"	new Ajax.Request(							\n"
		"		'ajax_servcmd', {						\n"
		"			method: 'post',						\n"
		"			parameters: 'g_cmd=DELE ' + msgnum1 + ',' + msgnum2,	\n"
		"			onComplete: RefreshQueueDisplay()			\n"
		"		}								\n"
		"	);									\n"
		"}										\n"
		"								\n"
		"</script>							\n"
	);

	wprintf("<div id=\"banner\">\n");
	wprintf("<h1>");
	wprintf(_("View the outbound SMTP queue"));
	wprintf("</h1>\n");
	wprintf("</div>\n");

	wprintf("<div id=\"content\" class=\"service\">\n");

	wprintf("<div class=\"fix_scrollbar_bug\">"
		"<table class=\"smtpqueue_background\">"
		"<tr><td valign=top>\n");

	wprintf("<div id=\"smtpqueue_inner_div\">");

	display_smtpqueue_inner_div();

	wprintf("</div>"
		"<div align=\"center\">"
		"<a href=\"javascript:RefreshQueueDisplay();\">%s</a>"
		"</div>"
		"</td></tr></table></div>\n", _("Refresh this page")
	);
	wDumpContent(1);

}




/*@}*/