110 |
#define CAPA_IMPLEMENTATION 0x00000200 |
#define CAPA_IMPLEMENTATION 0x00000200 |
111 |
|
|
112 |
static void pop_destroy __P ((mailbox_t)); |
static void pop_destroy __P ((mailbox_t)); |
113 |
|
static int pop_capa __P ((mailbox_t)); |
114 |
|
static int pop_stls __P ((mailbox_t)); |
115 |
|
|
116 |
/* Functions/Methods that implements the mailbox_t API. */ |
/* Functions/Methods that implements the mailbox_t API. */ |
117 |
static int pop_open __P ((mailbox_t, int)); |
static int pop_open __P ((mailbox_t, int)); |
395 |
} |
} |
396 |
} |
} |
397 |
|
|
398 |
|
/* |
399 |
|
POP3 CAPA support. |
400 |
|
*/ |
401 |
|
|
402 |
|
static int |
403 |
|
pop_capa (mailbox_t mbox) |
404 |
|
{ |
405 |
|
pop_data_t mpd = mbox->data; |
406 |
|
int status; |
407 |
|
|
408 |
|
status = pop_writeline (mpd, "CAPA\r\n"); |
409 |
|
CHECK_ERROR (mpd, status); |
410 |
|
MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); |
411 |
|
|
412 |
|
status = pop_write (mpd); |
413 |
|
CHECK_EAGAIN (mpd, status); |
414 |
|
mpd->state = POP_CAPA_ACK; |
415 |
|
|
416 |
|
/* POP_CAPA_ACK */ |
417 |
|
|
418 |
|
status = pop_read_ack (mpd); |
419 |
|
CHECK_EAGAIN (mpd, status); |
420 |
|
MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); |
421 |
|
|
422 |
|
if (!strncasecmp (mpd->buffer, "+OK", 3)) |
423 |
|
{ |
424 |
|
mpd->capa = 0; |
425 |
|
do |
426 |
|
{ |
427 |
|
status = pop_read_ack (mpd); |
428 |
|
MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); |
429 |
|
|
430 |
|
/* Here we check some common capabilities like TOP, USER, UIDL, |
431 |
|
and STLS. The rest are ignored. Please note that some |
432 |
|
capabilities might have an extra arguments. For instance, |
433 |
|
SASL can have CRAM-MD5 and/or KERBEROS_V4, and etc. |
434 |
|
This is why I suggest adding (in a future) an extra variable, |
435 |
|
for example `capa_sasl'. It would hold the following flags: |
436 |
|
SASL_CRAM_MD5, SASL_KERBEROS_V4, and so on. Also the EXPIRE |
437 |
|
and LOGIN-DELAY capabilities have an extra arguments! |
438 |
|
Note that there is no APOP capability, even though APOP |
439 |
|
is an optional command in POP3. -- W.P. */ |
440 |
|
|
441 |
|
if (!strncasecmp (mpd->buffer, "TOP", 3)) |
442 |
|
mpd->capa |= CAPA_TOP; |
443 |
|
else if (!strncasecmp (mpd->buffer, "USER", 4)) |
444 |
|
mpd->capa |= CAPA_USER; |
445 |
|
else if (!strncasecmp (mpd->buffer, "UIDL", 4)) |
446 |
|
mpd->capa |= CAPA_UIDL; |
447 |
|
else if (!strncasecmp (mpd->buffer, "STLS", 4)) |
448 |
|
mpd->capa |= CAPA_STLS; |
449 |
|
} |
450 |
|
while (mpd->nl); |
451 |
|
return status; |
452 |
|
} |
453 |
|
else |
454 |
|
{ |
455 |
|
/* mu_error ("CAPA not implemented\n"); */ /* FIXME */ |
456 |
|
return -1; |
457 |
|
} |
458 |
|
} |
459 |
|
|
460 |
/* Simple User/pass authentication for pop. We ask for the info |
/* Simple User/pass authentication for pop. We ask for the info |
461 |
from the standard input. */ |
from the standard input. */ |
462 |
int |
int |
619 |
return 0; |
return 0; |
620 |
} |
} |
621 |
|
|
622 |
static |
/* |
623 |
int |
Client side STLS support. |
624 |
tls (mailbox_t mbox) |
*/ |
625 |
|
|
626 |
|
static int |
627 |
|
pop_stls (mailbox_t mbox) |
628 |
{ |
{ |
629 |
#ifdef WITH_TLS |
#ifdef WITH_TLS |
630 |
pop_data_t mpd = mbox->data; |
pop_data_t mpd = mbox->data; |
633 |
|
|
634 |
if (!mu_tls_enable || !(mpd->capa & CAPA_STLS)) |
if (!mu_tls_enable || !(mpd->capa & CAPA_STLS)) |
635 |
return -1; |
return -1; |
636 |
|
|
637 |
status = pop_writeline (mpd, "STLS\r\n"); |
status = pop_writeline (mpd, "STLS\r\n"); |
638 |
CHECK_ERROR (mpd, status); |
CHECK_ERROR (mpd, status); |
639 |
status = pop_write (mpd); |
status = pop_write (mpd); |
654 |
return status; |
return status; |
655 |
#else |
#else |
656 |
return -1; |
return -1; |
657 |
#endif |
#endif /* WITH_TLS */ |
658 |
} |
} |
659 |
|
|
660 |
/* Open the connection to the sever, and send the authentication. */ |
/* Open the connection to the sever, and send the authentication. */ |
748 |
{ |
{ |
749 |
CHECK_ERROR_CLOSE (mbox, mpd, EACCES); |
CHECK_ERROR_CLOSE (mbox, mpd, EACCES); |
750 |
} |
} |
|
status = pop_writeline (mpd, "CAPA\r\n"); |
|
|
CHECK_ERROR (mpd, status); |
|
|
MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); |
|
751 |
mpd->state = POP_CAPA; |
mpd->state = POP_CAPA; |
752 |
} |
} |
753 |
|
|
754 |
case POP_CAPA: |
case POP_CAPA: |
|
status = pop_write (mpd); |
|
|
CHECK_EAGAIN (mpd, status); |
|
|
mpd->state = POP_CAPA_ACK; |
|
|
|
|
755 |
case POP_CAPA_ACK: |
case POP_CAPA_ACK: |
756 |
status = pop_read_ack (mpd); |
pop_capa (mbox); |
757 |
CHECK_EAGAIN (mpd, status); |
mpd->state = POP_STLS; |
|
MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); |
|
|
|
|
|
if (!strncasecmp (mpd->buffer, "+OK", 3)) |
|
|
{ |
|
|
mpd->capa = 0; |
|
|
do |
|
|
{ |
|
|
status = pop_read_ack (mpd); |
|
|
MAILBOX_DEBUG0 (mbox, MU_DEBUG_PROT, mpd->buffer); |
|
|
|
|
|
/* Here we check some common capabilities like TOP, USER, UIDL, |
|
|
and STLS. The rest are ignored. Please note that some |
|
|
capabilities might have an extra arguments. For instance, |
|
|
SASL can have CRAM-MD5 and/or KERBEROS_V4, and etc. |
|
|
This is why I suggest adding (in a future) an extra variable, |
|
|
for example `capa_sasl'. It would hold the following flags: |
|
|
SASL_CRAM_MD5, SASL_KERBEROS_V4, and so on. Also the EXPIRE |
|
|
and LOGIN-DELAY capabilities have an extra arguments! |
|
|
Note that there is no APOP capability, even though APOP |
|
|
is an optional command in POP3. -- W.P. */ |
|
|
|
|
|
if (!strncasecmp (mpd->buffer, "TOP", 3)) |
|
|
mpd->capa |= CAPA_TOP; |
|
|
else if (!strncasecmp (mpd->buffer, "USER", 4)) |
|
|
mpd->capa |= CAPA_USER; |
|
|
else if (!strncasecmp (mpd->buffer, "UIDL", 4)) |
|
|
mpd->capa |= CAPA_UIDL; |
|
|
else if (!strncasecmp (mpd->buffer, "STLS", 4)) |
|
|
mpd->capa |= CAPA_STLS; |
|
|
} |
|
|
while (mpd->nl); |
|
|
} |
|
|
/* else |
|
|
mu_error ("CAPA not implemented\n"); */ /* FIXME */ |
|
758 |
|
|
759 |
case POP_STLS: |
case POP_STLS: |
760 |
case POP_STLS_ACK: |
case POP_STLS_ACK: |
761 |
tls (mbox); |
status = pop_stls (mbox); |
762 |
|
if (status == 0) |
763 |
|
pop_capa (mbox); |
764 |
mpd->state = POP_AUTH; |
mpd->state = POP_AUTH; |
765 |
|
|
766 |
case POP_AUTH: |
case POP_AUTH: |