/[pkg-mixmaster]/trunk/Mix/Src/mail.c
ViewVC logotype

Contents of /trunk/Mix/Src/mail.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 345 - (show annotations) (download)
Thu Oct 10 10:15:55 2002 UTC (10 years, 7 months ago) by weaselp
File MIME type: text/plain
File size: 18475 byte(s)
snprintf() takes care of the final \0 itself
1 /* Mixmaster version 3 -- (C) 1999 Anonymizer Inc.
2
3 Mixmaster may be redistributed and modified under certain conditions.
4 This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
5 ANY KIND, either express or implied. See the file COPYRIGHT for
6 details.
7
8 Socket-based mail transport services
9 $Id: mail.c,v 1.16 2002/10/10 10:15:55 weaselp Exp $ */
10
11
12 #include "mix3.h"
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16
17 #if defined(UNIX) && defined(USE_SOCK)
18 #include <unistd.h>
19 #include <sys/types.h>
20 #include <sys/socket.h>
21 #include <netinet/in.h>
22 #include <arpa/inet.h>
23 #include <netdb.h>
24 #endif /* defined(UNIX) && defined(USE_SOCK) */
25
26 #include <fcntl.h>
27 #include <time.h>
28 #include <sys/stat.h>
29 #include <errno.h>
30
31
32 int sendinfofile(char *name, char *logname, BUFFER *address, BUFFER *header)
33 {
34 FILE *f = NULL, *log = NULL;
35 BUFFER *msg, *addr;
36 char line[LINELEN];
37 int ret = -1;
38
39 if (bufeq(address, ANONNAME))
40 return (0); /* don't reply to our own anon messages */
41 f = mix_openfile(name, "r");
42 if (f == NULL)
43 return (-1);
44
45 addr = buf_new();
46 rfc822_addr(address, addr);
47 if (addr->length == 0)
48 buf_set(addr, address), buf_nl(addr);
49
50 if (logname != NULL) {
51 if ((log = mix_openfile(logname, "r+")) != NULL) {
52 /* log recipients to prevent mail loop */
53 while (fgets(line, sizeof(line), log) != NULL)
54 if (strieq(line, addr->data))
55 goto end;
56 } else if ((log = mix_openfile(logname, "w")) == NULL) {
57 errlog(ERRORMSG, "Can't create %s.\n", logname);
58 ret = -1;
59 goto end;
60 }
61 fprintf(log, "%s", addr->data);
62 }
63 msg = buf_new();
64 if (header)
65 buf_cat(msg, header), buf_nl(msg);
66 while (fgets(line, sizeof(line), f) != NULL) {
67 if (streq(line, "DESTINATION-BLOCK\n"))
68 buf_appendf(msg, "destination-block %b", addr);
69 else
70 buf_appends(msg, line);
71 }
72 ret = sendmail(msg, REMAILERNAME, address);
73 buf_free(msg);
74 end:
75 if (f)
76 fclose(f);
77 if (log)
78 fclose(log);
79 buf_free(addr);
80 return (ret);
81 }
82
83 int smtpsend(BUFFER *head, BUFFER *message, char *from);
84
85
86 int sendmail_loop(BUFFER *message, char *from, BUFFER *address)
87 {
88 BUFFER *msg;
89 int err;
90
91 msg = buf_new();
92 buf_appendf(msg, "X-Loop: %s\n", REMAILERADDR);
93 buf_cat(msg, message);
94 err = sendmail(msg, from, address);
95 buf_free(msg);
96
97 return(err);
98 }
99
100 int sendmail(BUFFER *message, char *from, BUFFER *address)
101 {
102 /* returns: 0: ok 1: problem, try again -1: failed */
103
104 BUFFER *head, *block;
105 FILE *f;
106 int err = -1;
107
108 head = buf_new();
109
110 block = readdestblk( );
111 if ( !block ) block = buf_new( );
112
113 if (address != NULL &&
114 (address->length == 0 || doblock(address, block, 1) == -1))
115 goto end;
116
117 if (from != NULL) {
118 buf_setf(head, "From: %s", from);
119 hdr_encode(head, 255);
120 buf_nl(head);
121 }
122 if (address != NULL)
123 buf_appendf(head, "To: %b\n", address);
124
125 buf_rewind(message);
126
127 if (SMTPRELAY[0])
128 err = smtpsend(head, message, from);
129 else if (strieq(SENDMAIL, "outfile")) {
130 char path[PATHMAX];
131 FILE *f = NULL;
132 #ifdef SHORTNAMES
133 int i;
134 for (i = 0; i < 10000; i++) {
135 snprintf(path, PATHMAX, "%s%cout%i.txt", POOLDIR, DIRSEP, i);
136 f = fopen(path, "r");
137 if (f)
138 fclose(f);
139 else
140 break;
141 }
142 f = fopen(path, "w");
143 #else /* end of SHORTNAMES */
144 static unsigned long namecounter = 0;
145 struct stat statbuf;
146 int count;
147 char hostname[64];
148
149 hostname[0] = '\0';
150 gethostname(hostname, 63);
151 hostname[63] = '\0';
152
153 /* Step 2: Stat the file. Wait for ENOENT as a response. */
154 for (count = 0;; count++) {
155 snprintf(path, PATHMAX, "%s%cout.%lu.%u_%lu.%s,S=%lu.txt",
156 POOLDIR, DIRSEP, time(NULL), getpid(), namecounter++, hostname, head->length + message->length);
157
158 if (stat(path, &statbuf) == 0)
159 errno = EEXIST;
160 else if (errno == ENOENT) { /* create the file (at least try) */
161 f = fopen(path, "w");
162 if (f != NULL)
163 break; /* we managed to open the file */
164 }
165 if (count > 5)
166 break; /* Too many retries - give up */
167 #ifdef WIN32
168 Sleep(2000); /* sleep and retry */
169 #else /* end of WIN32 */
170 sleep(2); /* sleep and retry */
171 #endif /* else not WIN32 */
172 }
173 #endif /* else not SHORTNAMES */
174 if (f != NULL) {
175 err = buf_write(head, f);
176 err = buf_write(message, f);
177 fclose(f);
178 } else
179 errlog(ERRORMSG, "Can't create %s!\n", path);
180 } else {
181 if (SENDANONMAIL[0] != '\0' && (from == NULL || streq(from, ANONNAME)))
182 f = openpipe(SENDANONMAIL);
183 else
184 f = openpipe(SENDMAIL);
185 if (f != NULL) {
186 err = buf_write(head, f);
187 err = buf_write(message, f);
188 closepipe(f);
189 }
190 }
191 if (err != 0)
192 err = 1; /* error while sending, retry later */
193 end:
194 buf_free(block);
195 buf_free(head);
196 return (err);
197 }
198
199 /* socket communication **********************************************/
200
201 #ifdef USE_SOCK
202 #ifdef WIN32
203 WSADATA w;
204
205 int sock_init()
206 {
207 if (WSAStartup(MAKEWORD(2, 0), &w) != 0) {
208 errlog(ERRORMSG, "Unable to initialize WINSOCK.\n");
209 return 0;
210 }
211 return 1;
212 }
213
214 void sock_exit(void)
215 {
216 WSACleanup();
217 }
218 #endif /* WIN32 */
219
220 SOCKET opensocket(char *hostname, int port)
221 {
222 struct hostent *hp;
223 struct sockaddr_in server;
224 SOCKET s;
225
226 if ((hp = gethostbyname(hostname)) == NULL)
227 return (INVALID_SOCKET);
228
229 memset((char *) &server, 0, sizeof(server));
230 server.sin_family = AF_INET;
231 server.sin_addr.s_addr = *(unsigned long *) hp->h_addr;
232 server.sin_port = htons((unsigned short) port);
233
234 s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
235 if (s != INVALID_SOCKET)
236 if (connect(s, (struct sockaddr *) &server, sizeof(server)) < 0) {
237 closesocket(s);
238 return (INVALID_SOCKET);
239 }
240 return (s);
241 }
242
243 #ifndef WIN32
244 int closesocket(SOCKET s)
245 {
246 return (close(s));
247 }
248 #endif /* ifndef WIN32 */
249
250 int sock_getline(SOCKET s, BUFFER *line)
251 {
252 char c;
253 int ok;
254
255 buf_clear(line);
256 while ((ok = recv(s, &c, 1, 0)) > 0) {
257 if (c == '\n')
258 break;
259 if (c != '\r')
260 buf_appendc(line, c);
261 }
262 if (ok <= 0)
263 return (-1);
264 if (line->length == 0)
265 return (1);
266 return (0);
267 }
268
269 int sock_cat(SOCKET s, BUFFER *b)
270 {
271 int p = 0, n;
272
273 do {
274 n = send(s, b->data, b->length, 0);
275 if (n < 0)
276 return (-1);
277 p += n;
278 } while (p < b->length);
279 return (0);
280 }
281 #else /* end of USE_SOCK */
282 SOCKET opensocket(char *hostname, int port)
283 {
284 return (INVALID_SOCKET);
285 }
286
287 int closesocket(SOCKET s)
288 {
289 return (INVALID_SOCKET);
290 }
291
292 int sock_getline(SOCKET s, BUFFER *line)
293 {
294 return (-1);
295 }
296
297 int sock_cat(SOCKET s, BUFFER *b)
298 {
299 return (-1);
300 }
301 #endif /* else not USE_SOCK */
302
303 /* send messages by SMTP ************************************************/
304
305 static int sock_getsmtp(SOCKET s, BUFFER *response)
306 {
307 int ret;
308 BUFFER *line;
309 line = buf_new();
310
311 buf_clear(response);
312 do {
313 ret = sock_getline(s, line);
314 buf_cat(response, line);
315 } while (line->length >= 4 && line->data[3] == '-');
316 buf_free(line);
317 return (ret);
318 }
319
320 SOCKET smtp_open(void)
321 {
322 int s = INVALID_SOCKET;
323 int esmtp = 0;
324 BUFFER *line;
325
326 #ifdef USE_SOCK
327 if (SMTPRELAY[0] != '\0')
328 s = opensocket(SMTPRELAY, 25);
329 if (s != INVALID_SOCKET) {
330 line = buf_new();
331 sock_getsmtp(s, line);
332 if (bufifind(line, "ESMTP"))
333 esmtp = 1;
334 if (line->data[0] != '2') {
335 errlog(ERRORMSG, "SMTP relay not ready. %b\n", line);
336 closesocket(s);
337 s = INVALID_SOCKET;
338 } else {
339 errlog(DEBUGINFO, "Opening SMTP connection.\n");
340 if (esmtp)
341 buf_sets(line, "EHLO ");
342 else
343 buf_sets(line, "HELO ");
344 if (HELONAME[0])
345 buf_appends(line, HELONAME);
346 else if (strchr(ENVFROM, '@'))
347 buf_appends(line, strchr(ENVFROM, '@') + 1);
348 else {
349 struct sockaddr_in sa;
350 int len = sizeof(sa);
351 struct hostent *hp;
352
353 if (getsockname(s, (struct sockaddr *) &sa, &len) == 0 &&
354 (hp = gethostbyaddr((char *) &sa.sin_addr, sizeof(sa.sin_addr),
355 AF_INET)) != NULL)
356 buf_appends(line, (char *) hp->h_name);
357 else if (strchr(REMAILERADDR, '@'))
358 buf_appends(line, strchr(REMAILERADDR, '@') + 1);
359 else
360 buf_appends(line, SHORTNAME);
361 }
362 buf_chop(line);
363 buf_appends(line, "\r\n");
364 sock_cat(s, line);
365 sock_getsmtp(s, line);
366 if (line->data[0] != '2') {
367 errlog(ERRORMSG, "SMTP relay refuses HELO: %b\n", line);
368 closesocket(s);
369 s = INVALID_SOCKET;
370 } else if (SMTPUSERNAME[0] && esmtp && bufifind(line, "AUTH") && bufifind(line, "LOGIN")) {
371 buf_sets(line, "AUTH LOGIN\r\n");
372 sock_cat(s, line);
373 sock_getsmtp(s, line);
374 if (!bufleft(line, "334")) {
375 errlog(ERRORMSG, "SMTP AUTH fails: %b\n", line);
376 goto err;
377 }
378 buf_sets(line, SMTPUSERNAME);
379 encode(line, 0);
380 buf_appends(line, "\r\n");
381 sock_cat(s, line);
382 sock_getsmtp(s, line);
383 if (!bufleft(line, "334")) {
384 errlog(ERRORMSG, "SMTP username rejected: %b\n", line);
385 goto err;
386 }
387 buf_sets(line, SMTPPASSWORD);
388 encode(line, 0);
389 buf_appends(line, "\r\n");
390 sock_cat(s, line);
391 sock_getsmtp(s, line);
392 if (!bufleft(line, "235"))
393 errlog(ERRORMSG, "SMTP authentication failed: %b\n", line);
394 }
395 }
396 err:
397 buf_free(line);
398 }
399 #endif /* USE_SOCK */
400 return (s);
401 }
402
403 int smtp_close(SOCKET s)
404 {
405 BUFFER *line;
406 int ret = -1;
407
408 #ifdef USE_SOCK
409 line = buf_new();
410 buf_sets(line, "QUIT\r\n");
411 sock_cat(s, line);
412 if (sock_getsmtp(s, line) == 0 && line->data[0] == '2') {
413 errlog(DEBUGINFO, "Closing SMTP connection.\n");
414 ret = 0;
415 } else
416 errlog(WARNING, "SMTP quit failed: %b\n", line);
417 closesocket(s);
418 buf_free(line);
419 #endif /* USE_SOCK */
420 return (ret);
421 }
422
423 int smtp_send(SOCKET relay, BUFFER *head, BUFFER *message, char *from)
424 {
425 BUFFER *rcpt, *line, *field, *content;
426 int ret = -1;
427
428 #ifdef USE_SOCK
429 line = buf_new();
430 field = buf_new();
431 content = buf_new();
432 rcpt = buf_new();
433
434 while (buf_getheader(head, field, content) == 0)
435 if (bufieq(field, "to"))
436 #ifdef BROKEN_MTA
437 if (!bufifind(rcpt, content->data))
438 /* Do not add the same recipient twice.
439 Needed for brain-dead MTAs. */
440 #endif /* BROKEN_MTA */
441 rfc822_addr(content, rcpt);
442 buf_rewind(head);
443
444 while (buf_isheader(message) && buf_getheader(message, field, content) == 0) {
445 if (bufieq(field, "to") || bufieq(field, "cc") || bufieq(field, "bcc")) {
446 #ifdef BROKEN_MTA
447 if (!bufifind(rcpt, content->data))
448 /* Do not add the same recipient twice.
449 Needed for brain-dead MTAs. */
450 #endif /* BROKEN_MTA */
451 rfc822_addr(content, rcpt);
452 }
453 if (!bufieq(field, "bcc"))
454 buf_appendheader(head, field, content);
455 }
456 buf_nl(head);
457
458 buf_clear(content);
459 if (from) {
460 buf_sets(line, from);
461 rfc822_addr(line, content);
462 buf_chop(content);
463 }
464 if (bufieq(content, REMAILERADDR) || bufieq(content, ANONADDR))
465 buf_clear(content);
466 if (content->length == 0)
467 buf_sets(content, ENVFROM[0] ? ENVFROM : ANONADDR);
468
469 buf_setf(line, "MAIL FROM:<%b>\r\n", content);
470 sock_cat(relay, line);
471 sock_getsmtp(relay, line);
472 if (!line->data[0] == '2') {
473 errlog(ERRORMSG, "SMTP relay does not accept mail: %b\n", line);
474 goto end;
475 }
476 while (buf_getline(rcpt, content) == 0) {
477 buf_setf(line, "RCPT TO:<%b>\r\n", content);
478 sock_cat(relay, line);
479 sock_getsmtp(relay, line);
480 if (bufleft(line, "421")) {
481 errlog(ERRORMSG, "SMTP relay error: %b\n", line);
482 goto end;
483 }
484 if (bufleft(line, "530")) {
485 errlog(ERRORMSG, "SMTP authentication required: %b\n", line);
486 goto end;
487 }
488 }
489
490 buf_sets(line, "DATA\r\n");
491 sock_cat(relay, line);
492 sock_getsmtp(relay, line);
493 if (!bufleft(line, "354")) {
494 errlog(WARNING, "SMTP relay does not accept message: %b\n", line);
495 goto end;
496 }
497 while (buf_getline(head, line) >= 0) {
498 buf_appends(line, "\r\n");
499 if (bufleft(line, ".")) {
500 buf_setf(content, ".%b", line);
501 buf_move(line, content);
502 }
503 sock_cat(relay, line);
504 }
505 while (buf_getline(message, line) >= 0) {
506 buf_appends(line, "\r\n");
507 if (bufleft(line, ".")) {
508 buf_setf(content, ".%b", line);
509 buf_move(line, content);
510 }
511 sock_cat(relay, line);
512 }
513 buf_sets(line, ".\r\n");
514 sock_cat(relay, line);
515 sock_getsmtp(relay, line);
516 if (bufleft(line, "2"))
517 ret = 0;
518 else
519 errlog(WARNING, "SMTP relay will not send message: %b\n", line);
520 end:
521 buf_free(line);
522 buf_free(field);
523 buf_free(content);
524 buf_free(rcpt);
525 #endif /* USE_SOCK */
526 return (ret);
527 }
528
529 static SOCKET sendmail_state = INVALID_SOCKET;
530
531 void sendmail_begin(void)
532 {
533 /* begin mail sending session */
534 if (sendmail_state == INVALID_SOCKET)
535 sendmail_state = smtp_open();
536 }
537 void sendmail_end(void)
538 {
539 /* end mail sending session */
540 if (sendmail_state != INVALID_SOCKET) {
541 smtp_close(sendmail_state);
542 sendmail_state = INVALID_SOCKET;
543 }
544 }
545
546 int smtpsend(BUFFER *head, BUFFER *message, char *from)
547 {
548 SOCKET s;
549 int ret = -1;
550
551 if (sendmail_state != INVALID_SOCKET)
552 ret = smtp_send(sendmail_state, head, message, from);
553 else {
554 s = smtp_open();
555 if (s != INVALID_SOCKET) {
556 ret = smtp_send(s, head, message, from);
557 smtp_close(s);
558 }
559 }
560 return (ret);
561 }
562
563 /* retrieve mail with POP3 **********************************************/
564 #ifdef USE_SOCK
565 int pop3_close(SOCKET s);
566
567 #define POP3_ANY 0
568 #define POP3_APOP 1
569 #define POP3_PASS 2
570
571 SOCKET pop3_open(char *user, char *host, char *pass, int auth)
572 {
573 SOCKET server = INVALID_SOCKET;
574 BUFFER *line;
575 int authenticated = 0;
576 char md[33];
577 int c;
578
579 line = buf_new();
580 server = opensocket(host, 110);
581 if (server == INVALID_SOCKET)
582 errlog(NOTICE, "Can't connect to POP3 server %s.\n", host);
583 else {
584 sock_getline(server, line);
585 if (!bufleft(line, "+")) {
586 errlog(WARNING, "No POP3 service at %s.\n", host);
587 closesocket(server);
588 server = INVALID_SOCKET;
589 }
590 }
591 if (server != INVALID_SOCKET) {
592 errlog(DEBUGINFO, "Opening POP3 connection to %s.\n", host);
593 do
594 c = buf_getc(line);
595 while (c != '<' && c != -1);
596 while (c != '>' && c != -1) {
597 buf_appendc(line, c);
598 c = buf_getc(line);
599 }
600 if (c == '>' && (auth == POP3_ANY || auth == POP3_APOP)) {
601 buf_appendc(line, c);
602 buf_appends(line, pass);
603 digest_md5(line, line);
604 id_encode(line->data, md);
605 buf_setf(line, "APOP %s %s\r\n", user, md);
606 sock_cat(server, line);
607 sock_getline(server, line);
608 if (bufleft(line, "+"))
609 authenticated = 1;
610 else {
611 errlog(auth == POP3_APOP ? ERRORMSG : NOTICE,
612 "POP3 APOP auth at %s failed: %b\n", host, line);
613 buf_sets(line, "QUIT\r\n");
614 sock_cat(server, line);
615 closesocket(server);
616 server = pop3_open(user, host, pass, POP3_PASS);
617 goto end;
618 }
619 }
620 if (!authenticated) {
621 buf_setf(line, "USER %s\r\n", user);
622 sock_cat(server, line);
623 sock_getline(server, line);
624 if (!bufleft(line, "+"))
625 errlog(ERRORMSG, "POP3 USER command at %s failed: %b\n", host, line);
626 else {
627 buf_setf(line, "PASS %s\r\n", pass);
628 sock_cat(server, line);
629 sock_getline(server, line);
630 if (bufleft(line, "+"))
631 authenticated = 1;
632 else
633 errlog(ERRORMSG, "POP3 auth at %s failed: %b\n", host, line);
634 }
635 }
636 if (!authenticated) {
637 pop3_close(server);
638 closesocket(server);
639 server = INVALID_SOCKET;
640 }
641 }
642 end:
643 buf_free(line);
644 return (server);
645 }
646
647 int pop3_close(SOCKET s)
648 {
649 BUFFER *line;
650 int ret = -1;
651
652 line = buf_new();
653 buf_sets(line, "QUIT\r\n");
654 sock_cat(s, line);
655 sock_getline(s, line);
656 if (bufleft(line, "+")) {
657 ret = 0;
658 errlog(DEBUGINFO, "Closing POP3 connection.\n");
659 } else
660 errlog(ERRORMSG, "POP3 QUIT failed:\n", line->data);
661 buf_free(line);
662 return (ret);
663 }
664
665 int pop3_stat(SOCKET s)
666 {
667 BUFFER *line;
668 int val = -1;
669
670 line = buf_new();
671 buf_sets(line, "STAT\r\n");
672 sock_cat(s, line);
673 sock_getline(s, line);
674 if (bufleft(line, "+"))
675 sscanf(line->data, "+%*s %d", &val);
676 buf_free(line);
677 return (val);
678 }
679
680 int pop3_list(SOCKET s, int n)
681 {
682 BUFFER *line;
683 int val = -1;
684
685 line = buf_new();
686 buf_setf(line, "LIST %d\r\n", n);
687 sock_cat(s, line);
688 sock_getline(s, line);
689 if (bufleft(line, "+"))
690 sscanf(line->data, "+%*s %d", &val);
691 buf_free(line);
692 return (val);
693 }
694
695 int pop3_dele(SOCKET s, int n)
696 {
697 BUFFER *line;
698 int ret = 0;
699
700 line = buf_new();
701 buf_setf(line, "DELE %d\r\n", n);
702 sock_cat(s, line);
703 sock_getline(s, line);
704 if (!bufleft(line, "+"))
705 ret = -1;
706 buf_free(line);
707 return (ret);
708 }
709
710 int pop3_retr(SOCKET s, int n, BUFFER *msg)
711 {
712 BUFFER *line;
713 int ret = -1;
714
715 line = buf_new();
716 buf_clear(msg);
717 buf_setf(line, "RETR %d\r\n", n);
718 sock_cat(s, line);
719 sock_getline(s, line);
720 if (bufleft(line, "+")) {
721 for (;;) {
722 if (sock_getline(s, line) == -1)
723 break;
724 if (bufeq(line, ".")) {
725 ret = 0;
726 break;
727 } else if (bufleft(line, ".")) {
728 buf_append(msg, line->data + 1, line->length - 1);
729 } else
730 buf_cat(msg, line);
731 buf_nl(msg);
732 }
733 }
734 buf_free(line);
735 return (ret);
736 }
737
738 void pop3get(void)
739 {
740 FILE *f;
741 char cfg[LINELEN], user[LINELEN], host[LINELEN], pass[LINELEN], auth[5];
742 SOCKET server;
743 BUFFER *line, *msg;
744 int i = 0, num = 0;
745
746 line = buf_new();
747 msg = buf_new();
748 f = mix_openfile(POP3CONF, "r");
749 if (f != NULL)
750 while (fgets(cfg, sizeof(cfg), f) != NULL) {
751 if (cfg[0] == '#')
752 continue;
753 if (strchr(cfg, '@'))
754 strchr(cfg, '@')[0] = ' ';
755 if (sscanf(cfg, "%127s %127s %127s %4s", user, host, pass, auth) < 3)
756 continue;
757 i = POP3_ANY;
758 if (strileft(auth, "apop"))
759 i = POP3_APOP;
760 if (strileft(auth, "pass"))
761 i = POP3_PASS;
762 server = pop3_open(user, host, pass, i);
763 if (server != INVALID_SOCKET) {
764 num = pop3_stat(server);
765 if (num < 0)
766 errlog(WARNING, "POP3 protocol error at %s.\n", host);
767 else if (num == 0)
768 errlog(DEBUGINFO, "No mail at %s.\n", host);
769 else
770 for (i = 1; i <= num; i++) {
771 if (POP3SIZELIMIT > 0 &&
772 pop3_list(server, i) > POP3SIZELIMIT * 1024) {
773 errlog(WARNING, "Over size message on %s.", host);
774 if (POP3DEL == 1)
775 pop3_dele(server, i);
776 } else {
777 if (pop3_retr(server, i, msg) == 0 &&
778 pool_add(msg, "inf") == 0)
779 pop3_dele(server, i);
780 else {
781 errlog(WARNING, "POP3 error while getting mail from %s.",
782 host);
783 closesocket(server);
784 goto end;
785 }
786 }
787 }
788 pop3_close(server);
789 closesocket(server);
790 }
791 }
792 end:
793 if (f != NULL)
794 fclose(f);
795 buf_free(line);
796 buf_free(msg);
797 }
798 #endif /* USE_SOCK */

  ViewVC Help
Powered by ViewVC 1.1.5