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

  ViewVC Help
Powered by ViewVC 1.1.5