Fetch messages and save them in $spool_file.
513{
515 if (!c_pop_host)
516 {
518 return;
519 }
520
521 char buf[1024] = { 0 };
522 char msgbuf[128] = { 0 };
523 int last = 0, msgs = 0, bytes = 0, rset = 0, rc;
525
527 char *url = p;
529 {
530 strcpy(url, "pop://");
531 p = strchr(url, '\0');
532 }
533 strcpy(p, c_pop_host);
534
537 if (rc)
538 {
539 mutt_error(
_(
"%s is an invalid POP path"), c_pop_host);
540 return;
541 }
542
544 if (!conn)
545 return;
546
549
551 {
553 return;
554 }
555
557
558
561 if (rc == -1)
562 goto fail;
563 if (rc == -2)
564 {
566 goto finish;
567 }
568
569 sscanf(buf, "+OK %d %d", &msgs, &bytes);
570
571
573 if ((msgs > 0) && c_pop_last)
574 {
577 if (rc == -1)
578 goto fail;
579 if (rc == 0)
580 sscanf(buf, "+OK %d", &last);
581 }
582
583 if (msgs <= last)
584 {
586 goto finish;
587 }
588
591
593 {
595 goto finish;
596 }
597 bool old_append = m_spool->
append;
599
602
603 snprintf(msgbuf, sizeof(msgbuf),
604 ngettext("Reading new messages (%d byte)...",
605 "Reading new messages (%d bytes)...", bytes),
606 bytes);
608
609 for (int i = last + 1; i <= msgs; i++)
610 {
612 if (msg)
613 {
614 snprintf(buf, sizeof(buf), "RETR %d\r\n", i);
616 if (rc == -3)
617 rset = 1;
618
620 {
621 rset = 1;
622 rc = -3;
623 }
624
626 }
627 else
628 {
629 rc = -3;
630 }
631
632 if ((rc == 0) && (delanswer ==
MUTT_YES))
633 {
634
635 snprintf(buf, sizeof(buf), "DELE %d\r\n", i);
637 }
638
639 if (rc == -1)
640 {
641 m_spool->
append = old_append;
643 goto fail;
644 }
645 if (rc == -2)
646 {
648 break;
649 }
650 if (rc == -3)
651 {
653 break;
654 }
655
656
657
659 "%s [%d of %d messages read]", msgs - last),
660 msgbuf, i - last, msgs - last);
661 }
662
663 m_spool->
append = old_append;
665
666 if (rset)
667 {
668
670 if (
pop_query(adata, buf,
sizeof(buf)) == -1)
671 goto fail;
672 }
673
674finish:
675
677 if (
pop_query(adata, buf,
sizeof(buf)) == -1)
678 goto fail;
681 return;
682
683fail:
687}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
void pop_adata_free(void **ptr)
Free the private Account data - Implements Account::adata_free() -.
#define mutt_message(...)
#define MUTT_MEM_CALLOC(n, type)
struct Connection * mutt_conn_find(const struct ConnAccount *cac)
Find a connection from a list.
int mx_msg_close(struct Mailbox *m, struct Message **ptr)
Close a message.
bool mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
struct Message * mx_msg_open_new(struct Mailbox *m, const struct Email *e, MsgOpenFlags flags)
Open a new message.
int mx_msg_commit(struct Mailbox *m, struct Message *msg)
Commit a message to a folder - Wrapper for MxOps::msg_commit()
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
enum MxStatus mx_mbox_close(struct Mailbox *m)
Save changes and close mailbox.
#define MUTT_ADD_FROM
add a From_ line
#define MUTT_OPEN_NO_FLAGS
No flags are set.
struct PopAccountData * pop_adata_new(void)
Create a new PopAccountData object.
int pop_open_connection(struct PopAccountData *adata)
Open connection and authenticate.
int pop_parse_path(const char *path, struct ConnAccount *cac)
Parse a POP mailbox name.
QuadOption
Possible values for a quad-option.
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
enum QuadOption query_quadoption(const char *prompt, struct ConfigSubset *sub, const char *name)
Ask the user a quad-question.
int mutt_socket_close(struct Connection *conn)
Close a socket.
Login details for a remote server.
bool append
Mailbox is opened in append mode.
A local copy of an email.
FILE * fp
pointer to the message data
enum UrlScheme url_check_scheme(const char *str)
Check the protocol of a URL.
@ U_UNKNOWN
Url wasn't recognised.