]> Pileus Git - ~andy/fetchmail/blob - pop3.c
Bug fixes.
[~andy/fetchmail] / pop3.c
1 /*
2  * pop3.c -- POP3 protocol methods
3  *
4  * Copyright 1998 by Eric S. Raymond.
5  * For license terms, see the file COPYING in this directory.
6  */
7
8 #include  "config.h"
9 #ifdef POP3_ENABLE
10 #include  <stdio.h>
11 #include  <string.h>
12 #include  <ctype.h>
13 #if defined(HAVE_UNISTD_H)
14 #include <unistd.h>
15 #endif
16 #if defined(STDC_HEADERS)
17 #include  <stdlib.h>
18 #endif
19  
20 #include  "fetchmail.h"
21 #include  "socket.h"
22 #include  "i18n.h"
23
24 #if OPIE_ENABLE
25 #include <opie.h>
26 #endif /* OPIE_ENABLE */
27
28 #ifndef strstr          /* glibc-2.1 declares this as a macro */
29 extern char *strstr();  /* needed on sysV68 R3V7.1. */
30 #endif /* strstr */
31
32 static int last;
33 #ifdef SDPS_ENABLE
34 char *sdps_envfrom;
35 char *sdps_envto;
36 #endif /* SDPS_ENABLE */
37
38 #if OPIE_ENABLE
39 static char lastok[POPBUFSIZE+1];
40 #endif /* OPIE_ENABLE */
41
42 #define DOTLINE(s)      (s[0] == '.' && (s[1]=='\r'||s[1]=='\n'||s[1]=='\0'))
43
44 static int pop3_ok (int sock, char *argbuf)
45 /* parse command response */
46 {
47     int ok;
48     char buf [POPBUFSIZE+1];
49     char *bufp;
50
51     if ((ok = gen_recv(sock, buf, sizeof(buf))) == 0)
52     {   bufp = buf;
53         if (*bufp == '+' || *bufp == '-')
54             bufp++;
55         else
56             return(PS_PROTOCOL);
57
58         while (isalpha(*bufp))
59             bufp++;
60
61         if (*bufp)
62           *(bufp++) = '\0';
63
64         if (strcmp(buf,"+OK") == 0)
65         {
66 #if OPIE_ENABLE
67             strcpy(lastok, bufp);
68 #endif /* OPIE_ENABLE */
69             ok = 0;
70         }
71         else if (strncmp(buf,"-ERR", 4) == 0)
72         {
73             if (stage > STAGE_GETAUTH) 
74                 ok = PS_PROTOCOL;
75             /*
76              * We're checking for "lock busy", "unable to lock", 
77              * "already locked", "wait a few minutes" etc. here. 
78              * This indicates that we have to wait for the server to
79              * unwedge itself before we can poll again.
80              *
81              * PS_LOCKBUSY check empirically verified with two recent
82              * versions of the Berkeley popper; QPOP (version 2.2)  and
83              * QUALCOMM Pop server derived from UCB (version 2.1.4-R3)
84              * These are caught by the case-indifferent "lock" check.
85              * The "wait" catches "mail storage services unavailable,
86              * wait a few minutes and try again" on the InterMail server.
87              *
88              * If these aren't picked up on correctly, fetchmail will 
89              * think there is an authentication failure and wedge the
90              * connection in order to prevent futile polls.
91              *
92              * Gad, what a kluge.
93              */
94             else if (strstr(bufp,"lock")
95                      || strstr(bufp,"Lock")
96                      || strstr(bufp,"LOCK")
97                      || strstr(bufp,"wait")
98                      /* these are blessed by RFC 2449 */
99                      || strstr(bufp,"[IN-USE]")||strstr(bufp,"[LOGIN-DELAY]"))
100                 ok = PS_LOCKBUSY;
101             else if ((strstr(bufp,"Service")
102                      || strstr(bufp,"service"))
103                          && (strstr(bufp,"unavailable")))
104                 ok = PS_SERVBUSY;
105             else
106                 ok = PS_AUTHFAIL;
107             /*
108              * We always want to pass the user lock-busy messages, because
109              * they're red flags.  Other stuff (like AUTH failures on non-
110              * RFC1734 servers) only if we're debugging.
111              */
112             if (*bufp && (ok == PS_LOCKBUSY || outlevel >= O_MONITOR))
113               report(stderr, "%s\n", bufp);
114         }
115         else
116             ok = PS_PROTOCOL;
117
118         if (argbuf != NULL)
119             strcpy(argbuf,bufp);
120     }
121
122     return(ok);
123 }
124
125 static int pop3_getauth(int sock, struct query *ctl, char *greeting)
126 /* apply for connection authorization */
127 {
128     int ok;
129     char *start,*end;
130     char *msg;
131 #if OPIE_ENABLE
132     char *challenge;
133 #endif /* OPIE_ENABLE */
134
135 #ifdef SDPS_ENABLE
136     /*
137      * This needs to catch both demon.co.uk and demon.net.
138      * If we see either, and we're in multidrop mode, try to use
139      * the SDPS *ENV extension.
140      */
141     if (!(ctl->server.sdps) && MULTIDROP(ctl) && strstr(greeting, "demon."))
142         ctl->server.sdps = TRUE;
143 #endif /* SDPS_ENABLE */
144
145     switch (ctl->server.protocol) {
146     case P_POP3:
147 #ifdef RPA_ENABLE
148         /* CompuServe POP3 Servers as of 990730 want AUTH first for RPA */
149         if (strstr(ctl->remotename, "@compuserve.com"))
150         {
151             /* AUTH command should return a list of available mechanisms */
152             if (gen_transact(sock, "AUTH") == 0)
153             {
154                 char buffer[10];
155                 flag has_rpa = FALSE;
156
157                 while ((ok = gen_recv(sock, buffer, sizeof(buffer))) == 0)
158                 {
159                     if (DOTLINE(buffer))
160                         break;
161                     if (strncasecmp(buffer, "rpa", 3) == 0)
162                         has_rpa = TRUE;
163                 }
164                 if (has_rpa && !POP3_auth_rpa(ctl->remotename, 
165                                               ctl->password, sock))
166                     return(PS_SUCCESS);
167             }
168
169             return(PS_AUTHFAIL);
170         }
171 #endif /* RPA_ENABLE */
172
173         /*
174          * CAPA command may return a list including available
175          * authentication mechanisms.  if it doesn't, no harm done, we
176          * just fall back to a plain login.  Note that this code 
177          * latches the server's authentication type, so that in daemon mode
178          * the CAPA check only needs to be done once at start of run.
179          *
180          * APOP was introduced in RFC 1450, and CAPA not until
181          * RFC2449. So the < check is an easy way to prevent CAPA from
182          * being sent to the more primitive POP3 servers dating from
183          * RFC 1081 and RFC 1225, which seem more likely to choke on
184          * it.  This certainly catches IMAP-2000's POP3 gateway.
185          * 
186          * These authentication methods are blessed by RFC1734,
187          * describing the POP3 AUTHentication command.
188          */
189         if (ctl->server.authenticate == A_ANY 
190             && strchr(greeting, '<') 
191             && gen_transact(sock, "CAPA") == 0)
192         {
193 #if defined(GSSAPI)
194             flag has_gssapi = FALSE;
195 #endif /* defined(GSSAPI) */
196 #if defined(KERBEROS_V4) || defined(KERBEROS_V5)
197             flag has_kerberos = FALSE;
198 #endif /* defined(KERBEROS_V4) || defined(KERBEROS_V5) */
199             flag has_cram = FALSE;
200 #ifdef OPIE_ENABLE
201             flag has_otp = FALSE;
202 #endif /* OPIE_ENABLE */
203             char buffer[64];
204
205             /* determine what authentication methods we have available */
206             while ((ok = gen_recv(sock, buffer, sizeof(buffer))) == 0)
207             {
208                 if (DOTLINE(buffer))
209                     break;
210 #if defined(GSSAPI)
211                 if (strstr(buffer, "GSSAPI"))
212                     has_gssapi = TRUE;
213 #endif /* defined(GSSAPI) */
214 #if defined(KERBEROS_V4) || defined(KERBEROS_V5)
215                 if (strstr(buffer, "KERBEROS_V4"))
216                     has_kerberos = TRUE;
217 #endif /* defined(KERBEROS_V4) || defined(KERBEROS_V5) */
218 #ifdef OPIE_ENABLE
219                 if (strstr(buffer, "X-OTP"))
220                     has_otp = TRUE;
221 #endif /* OPIE_ENABLE */
222                 if (strstr(buffer, "CRAM-MD5"))
223                     has_cram = TRUE;
224             }
225
226             /*
227              * Here's where we set priorities.  Note that we must do tests
228              * in *reverse* order of desirability.
229              */
230             if (has_cram)
231                 ctl->server.authenticate = A_CRAM_MD5;
232 #ifdef OPIE_ENABLE
233             if (has_otp)
234                 ctl->server.authenticate = A_OTP;
235 #endif /* OPIE_ENABLE */
236 #if defined(GSSAPI)
237             if (has_gssapi)
238                 ctl->server.authenticate = A_GSSAPI;
239 #endif /* defined(GSSAPI) */
240 #if defined(KERBEROS_V4) || defined(KERBEROS_V5)
241             if (has_kerberos)
242                 ctl->server.authenticate = A_KERBEROS_V4;
243 #endif /* defined(KERBEROS_V4) || defined(KERBEROS_V5) */
244         }
245
246         /*
247          * OK, we have an authentication type now.
248          */
249 #if defined(KERBEROS_V4) || defined(KERBEROS_V5)
250         /* 
251          * Servers doing KPOP have to go through a dummy login sequence
252          * rather than doing SASL.
253          */
254         if (
255 #if INET6_ENABLE
256             ctl->server.service && (strcmp(ctl->server.service, KPOP_PORT)!=0)
257 #else /* INET6_ENABLE */
258             ctl->server.port != KPOP_PORT
259 #endif /* INET6_ENABLE */
260             && (ctl->server.authenticate == A_KERBEROS_V4
261              || ctl->server.authenticate == A_KERBEROS_V5))
262             return(do_rfc1731(sock, "AUTH", ctl->server.truename));
263 #endif /* defined(KERBEROS_V4) || defined(KERBEROS_V5) */
264 #if defined(GSSAPI)
265         if (ctl->server.authenticate==A_GSSAPI)
266             return(do_gssauth(sock, "AUTH", 
267                               ctl->server.truename, ctl->remotename));
268 #endif /* defined(GSSAPI) */
269 #ifdef OPIE_ENABLE
270         if (ctl->server.authenticate == A_OTP)
271             do_otp(sock, "AUTH", ctl);
272 #endif /* OPIE_ENABLE */
273         if (ctl->server.authenticate == A_CRAM_MD5)
274             return(do_cram_md5(sock, "AUTH", ctl));
275
276         /* ordinary validation, no one-time password or RPA */ 
277         gen_transact(sock, "USER %s", ctl->remotename);
278         strcpy(shroud, ctl->password);
279         ok = gen_transact(sock, "PASS %s", ctl->password);
280         shroud[0] = '\0';
281         break;
282
283     case P_APOP:
284         /* build MD5 digest from greeting timestamp + password */
285         /* find start of timestamp */
286         for (start = greeting;  *start != 0 && *start != '<';  start++)
287             continue;
288         if (*start == 0) {
289             report(stderr,
290                    _("Required APOP timestamp not found in greeting\n"));
291             return(PS_AUTHFAIL);
292         }
293
294         /* find end of timestamp */
295         for (end = start;  *end != 0  && *end != '>';  end++)
296             continue;
297         if (*end == 0 || end == start + 1) {
298             report(stderr, 
299                    _("Timestamp syntax error in greeting\n"));
300             return(PS_AUTHFAIL);
301         }
302         else
303             *++end = '\0';
304
305         /* copy timestamp and password into digestion buffer */
306         xalloca(msg, char *, (end-start+1) + strlen(ctl->password) + 1);
307         strcpy(msg,start);
308         strcat(msg,ctl->password);
309
310         strcpy(ctl->digest, MD5Digest((unsigned char *)msg));
311
312         ok = gen_transact(sock, "APOP %s %s", ctl->remotename, ctl->digest);
313         break;
314
315     case P_RPOP:
316         if ((ok = gen_transact(sock,"USER %s", ctl->remotename)) == 0)
317             ok = gen_transact(sock, "RPOP %s", ctl->password);
318         break;
319
320     default:
321         report(stderr, _("Undefined protocol request in POP3_auth\n"));
322         ok = PS_ERROR;
323     }
324
325     if (ok != 0)
326     {
327         /* maybe we detected a lock-busy condition? */
328         if (ok == PS_LOCKBUSY)
329             report(stderr, _("lock busy!  Is another session active?\n")); 
330
331         return(ok);
332     }
333
334     /*
335      * Empirical experience shows some server/OS combinations
336      * may need a brief pause even after any lockfiles on the
337      * server are released, to give the server time to finish
338      * copying back very large mailfolders from the temp-file...
339      * this is only ever an issue with extremely large mailboxes.
340      */
341     sleep(3); /* to be _really_ safe, probably need sleep(5)! */
342
343     /* we're peek-capable if use of TOP is enabled */
344     peek_capable = !(ctl->fetchall || ctl->keep);
345
346     /* we're approved */
347     return(PS_SUCCESS);
348 }
349
350 static int pop3_gettopid( int sock, int num , char *id)
351 {
352     int ok;
353     int got_it;
354     char buf [POPBUFSIZE+1];
355     sprintf( buf, "TOP %d 1", num );
356     if ((ok = gen_transact(sock, buf )) != 0)
357        return ok; 
358     got_it = 0;
359     while ((ok = gen_recv(sock, buf, sizeof(buf))) == 0) 
360     {
361         if (DOTLINE(buf))
362             break;
363         if ( ! got_it && ! strncasecmp("Message-Id:", buf, 11 )) {
364             got_it = 1;
365             /* prevent stack overflows */
366             buf[IDLEN+12] = 0;
367             sscanf( buf+12, "%s", id);
368         }
369     }
370     return 0;
371 }
372
373 static int pop3_slowuidl( int sock,  struct query *ctl, int *countp, int *newp)
374 {
375     /* This approach tries to get the message headers from the
376      * remote hosts and compares the message-id to the already known
377      * ones:
378      *  + if the first message containes a new id, all messages on
379      *    the server will be new
380      *  + if the first is known, try to estimate the last known message
381      *    on the server and check. If this works you know the total number
382      *    of messages to get.
383      *  + Otherwise run a binary search to determine the last known message
384      */
385     int ok, nolinear = 0;
386     int first_nr, list_len, try_id, try_nr, add_id;
387     int num;
388     char id [IDLEN+1];
389     
390     if( (ok = pop3_gettopid( sock, 1, id )) != 0 )
391         return ok;
392     
393     if( ( first_nr = str_nr_in_list(&ctl->oldsaved, id) ) == -1 ) {
394         /* the first message is unknown -> all messages are new */
395         *newp = *countp;        
396         return 0;
397     }
398
399     /* check where we expect the latest known message */
400     list_len = count_list( &ctl->oldsaved );
401     try_id = list_len  - first_nr; /* -1 + 1 */
402     if( try_id > 1 ) {
403         if( try_id <= *countp ) {
404             if( (ok = pop3_gettopid( sock, try_id, id )) != 0 )
405                 return ok;
406     
407             try_nr = str_nr_last_in_list(&ctl->oldsaved, id);
408         } else {
409             try_id = *countp+1;
410             try_nr = -1;
411         }
412         if( try_nr != list_len -1 ) {
413             /* some messages inbetween have been deleted... */
414             if( try_nr == -1 ) {
415                 nolinear = 1;
416
417                 for( add_id = 1<<30; add_id > try_id-1; add_id >>= 1 )
418                     ;
419                 for( ; add_id; add_id >>= 1 ) {
420                     if( try_nr == -1 ) {
421                         if( try_id - add_id <= 1 ) {
422                             continue;
423                         }
424                         try_id -= add_id;
425                     } else 
426                         try_id += add_id;
427                     
428                     if( (ok = pop3_gettopid( sock, try_id, id )) != 0 )
429                         return ok;
430                     try_nr = str_nr_in_list(&ctl->oldsaved, id);
431                 }
432                 if( try_nr == -1 ) {
433                     try_id--;
434                 }
435             } else {
436                 report(stderr, 
437                        _("Messages inserted into list on server. Cannot handle this.\n"));
438                 return -1;
439             }
440         } 
441     }
442     /* the first try_id messages are known -> copy them to the newsaved list */
443     for( num = first_nr; num < list_len; num++ )
444     {
445         struct idlist   *new = save_str(&ctl->newsaved, 
446                                 str_from_nr_list(&ctl->oldsaved, num),
447                                 UID_UNSEEN);
448         new->val.status.num = num - first_nr + 1;
449     }
450
451     if( nolinear ) {
452         free_str_list(&ctl->oldsaved);
453         ctl->oldsaved = 0;
454         last = try_id;
455     }
456
457     *newp = *countp - try_id;
458     return 0;
459 }
460
461 static int pop3_getrange(int sock, 
462                          struct query *ctl,
463                          const char *folder,
464                          int *countp, int *newp, int *bytes)
465 /* get range of messages to be fetched */
466 {
467     int ok;
468     char buf [POPBUFSIZE+1];
469
470     /* Ensure that the new list is properly empty */
471     ctl->newsaved = (struct idlist *)NULL;
472
473 #ifdef MBOX
474     /* Alain Knaff suggests this, but it's not RFC standard */
475     if (folder)
476         if ((ok = gen_transact(sock, "MBOX %s", folder)))
477             return ok;
478 #endif /* MBOX */
479
480     /* get the total message count */
481     gen_send(sock, "STAT");
482     ok = pop3_ok(sock, buf);
483     if (ok == 0)
484         sscanf(buf,"%d %d", countp, bytes);
485     else
486         return(ok);
487
488     /*
489      * Newer, RFC-1725-conformant POP servers may not have the LAST command.
490      * We work as hard as possible to hide this ugliness, but it makes 
491      * counting new messages intrinsically quadratic in the worst case.
492      */
493     last = 0;
494     *newp = -1;
495     if (*countp > 0 && !ctl->fetchall)
496     {
497         char id [IDLEN+1];
498
499         if (!ctl->server.uidl) {
500             gen_send(sock, "LAST");
501             ok = pop3_ok(sock, buf);
502         } else
503             ok = 1;
504         if (ok == 0)
505         {
506             if (sscanf(buf, "%d", &last) == 0)
507             {
508                 report(stderr, _("protocol error\n"));
509                 return(PS_ERROR);
510             }
511             *newp = (*countp - last);
512         }
513         else
514         {
515             /* grab the mailbox's UID list */
516             if ((ok = gen_transact(sock, "UIDL")) != 0)
517             {
518                 /* don't worry, yet! do it the slow way */
519                 if((ok = pop3_slowuidl( sock, ctl, countp, newp))!=0)
520                 {
521                     report(stderr, _("protocol error while fetching UIDLs\n"));
522                     return(PS_ERROR);
523                 }
524             }
525             else
526             {
527                 int     num;
528
529                 *newp = 0;
530                 while ((ok = gen_recv(sock, buf, sizeof(buf))) == 0)
531                 {
532                     if (DOTLINE(buf))
533                         break;
534                     else if (sscanf(buf, "%d %s", &num, id) == 2)
535                     {
536                         struct idlist   *new;
537
538                         new = save_str(&ctl->newsaved, id, UID_UNSEEN);
539                         new->val.status.num = num;
540
541                         if (str_in_list(&ctl->oldsaved, id, FALSE)) {
542                             new->val.status.mark = UID_SEEN;
543                             str_set_mark(&ctl->oldsaved, id, UID_SEEN);
544                         }
545                         else
546                             (*newp)++;
547                     }
548                 }
549             }
550         }
551     }
552
553     return(PS_SUCCESS);
554 }
555
556 static int pop3_getsizes(int sock, int count, int *sizes)
557 /* capture the sizes of all messages */
558 {
559     int ok;
560
561     if ((ok = gen_transact(sock, "LIST")) != 0)
562         return(ok);
563     else
564     {
565         char buf [POPBUFSIZE+1];
566
567         while ((ok = gen_recv(sock, buf, sizeof(buf))) == 0)
568         {
569             int num, size;
570
571             if (DOTLINE(buf))
572                 break;
573             else if (sscanf(buf, "%d %d", &num, &size) == 2)
574                 sizes[num - 1] = size;
575         }
576
577         return(ok);
578     }
579 }
580
581 static int pop3_is_old(int sock, struct query *ctl, int num)
582 /* is the given message old? */
583 {
584     if (!ctl->oldsaved)
585         return (num <= last);
586     else
587         return (str_in_list(&ctl->oldsaved,
588                             str_find(&ctl->newsaved, num), FALSE));
589 }
590
591 #ifdef UNUSED
592 /*
593  * We could use this to fetch headers only as we do for IMAP.  The trouble 
594  * is that there's no way to fetch the body only.  So the following RETR 
595  * would have to re-fetch the header.  Enough messages have longer headers
596  * than bodies to make this a net loss.
597  */
598 static int pop_fetch_headers(int sock, struct query *ctl,int number,int *lenp)
599 /* request headers of nth message */
600 {
601     int ok;
602     char buf[POPBUFSIZE+1];
603
604     gen_send(sock, "TOP %d 0", number);
605     if ((ok = pop3_ok(sock, buf)) != 0)
606         return(ok);
607
608     *lenp = -1;         /* we got sizes from the LIST response */
609
610     return(PS_SUCCESS);
611 }
612 #endif /* UNUSED */
613
614 static int pop3_fetch(int sock, struct query *ctl, int number, int *lenp)
615 /* request nth message */
616 {
617     int ok;
618     char buf[POPBUFSIZE+1];
619
620 #ifdef SDPS_ENABLE
621     /*
622      * See http://www.demon.net/services/mail/sdps-tech.html
623      * for a description of what we're parsing here.
624      */
625     if (ctl->server.sdps)
626     {
627         int     linecount = 0;
628
629         sdps_envfrom = (char *)NULL;
630         sdps_envto = (char *)NULL;
631         gen_send(sock, "*ENV %d", number);
632         do {
633             if (gen_recv(sock, buf, sizeof(buf)))
634             {
635                 break;
636             }
637             linecount++;
638             switch (linecount) {
639             case 4:
640                 /* No need to wrap envelope from address */
641                 sdps_envfrom = xmalloc(strlen(buf)+1);
642                 strcpy(sdps_envfrom,buf);
643                 break;
644             case 5:
645                 /* Wrap address with To: <> so nxtaddr() likes it */
646                 sdps_envto = xmalloc(strlen(buf)+7);
647                 sprintf(sdps_envto,"To: <%s>",buf);
648                 break;
649             }
650         } while
651             (!(buf[0] == '.' && (buf[1] == '\r' || buf[1] == '\n' || buf[1] == '\0')));
652     }
653 #endif /* SDPS_ENABLE */
654
655     /*
656      * Though the POP RFCs don't document this fact, on almost every
657      * POP3 server I know of messages are marked "seen" only at the
658      * time the OK response to a RETR is issued.
659      *
660      * This means we can use TOP to fetch the message without setting its
661      * seen flag.  This is good!  It means that if the protocol exchange
662      * craps out during the message, it will still be marked `unseen' on
663      * the server.  (Exception: in early 1999 SpryNet's POP3 servers were
664      * reported to mark messages seen on a TOP fetch.)
665      *
666      * However...*don't* do this if we're using keep to suppress deletion!
667      * In that case, marking the seen flag is the only way to prevent the
668      * message from being re-fetched on subsequent runs.
669      *
670      * Also use RETR if fetchall is on.  This gives us a workaround
671      * for servers like usa.net's that bungle TOP.  It's pretty
672      * harmless because fetchall guarantees that any message dropped
673      * by an interrupted RETR will be picked up on the next poll of the
674      * site.
675      *
676      * We take advantage here of the fact that, according to all the
677      * POP RFCs, "if the number of lines requested by the POP3 client
678      * is greater than than the number of lines in the body, then the
679      * POP3 server sends the entire message.").
680      *
681      * The line count passed (99999999) is the maximum value CompuServe will
682      * accept; it's much lower than the natural value 2147483646 (the maximum
683      * twos-complement signed 32-bit integer minus 1) */
684     if (ctl->keep || ctl->fetchall)
685         gen_send(sock, "RETR %d", number);
686     else
687         gen_send(sock, "TOP %d 99999999", number);
688     if ((ok = pop3_ok(sock, buf)) != 0)
689         return(ok);
690
691     *lenp = -1;         /* we got sizes from the LIST response */
692
693     return(PS_SUCCESS);
694 }
695
696 static int pop3_delete(int sock, struct query *ctl, int number)
697 /* delete a given message */
698 {
699     /* actually, mark for deletion -- doesn't happen until QUIT time */
700     return(gen_transact(sock, "DELE %d", number));
701 }
702
703 static int pop3_logout(int sock, struct query *ctl)
704 /* send logout command */
705 {
706     int ok;
707
708     ok = gen_transact(sock, "QUIT");
709     if (!ok)
710         expunge_uids(ctl);
711
712     if (ctl->lastid)
713     {
714         free(ctl->lastid);
715         ctl->lastid = NULL;
716     }
717
718     return(ok);
719 }
720
721 const static struct method pop3 =
722 {
723     "POP3",             /* Post Office Protocol v3 */
724 #if INET6_ENABLE
725     "pop3",             /* standard POP3 port */
726     "pop3s",            /* ssl POP3 port */
727 #else /* INET6_ENABLE */
728     110,                /* standard POP3 port */
729     995,                /* ssl POP3 port */
730 #endif /* INET6_ENABLE */
731     FALSE,              /* this is not a tagged protocol */
732     TRUE,               /* this uses a message delimiter */
733     pop3_ok,            /* parse command response */
734     pop3_getauth,       /* get authorization */
735     pop3_getrange,      /* query range of messages */
736     pop3_getsizes,      /* we can get a list of sizes */
737     pop3_is_old,        /* how do we tell a message is old? */
738     pop3_fetch,         /* request given message */
739     NULL,               /* no way to fetch body alone */
740     NULL,               /* no message trailer */
741     pop3_delete,        /* how to delete a message */
742     pop3_logout,        /* log out, we're done */
743     FALSE,              /* no, we can't re-poll */
744 };
745
746 int doPOP3 (struct query *ctl)
747 /* retrieve messages using POP3 */
748 {
749 #ifndef MBOX
750     if (ctl->mailboxes->id) {
751         fprintf(stderr,_("Option --remote is not supported with POP3\n"));
752         return(PS_SYNTAX);
753     }
754 #endif /* MBOX */
755     peek_capable = !ctl->fetchall;
756     return(do_protocol(ctl, &pop3));
757 }
758 #endif /* POP3_ENABLE */
759
760 /* pop3.c ends here */