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