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