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