Fetch messages and save them in $spool_file.
530{
532 if (!c_pop_host)
533 {
535 return;
536 }
537
538 char buf[1024] = { 0 };
539 char msgbuf[128] = { 0 };
540 int last = 0, msgs = 0, bytes = 0, rset = 0, rc;
542
544 char *url = p;
546 {
547 strcpy(url, "pop://");
548 p = strchr(url, '\0');
549 }
550 strcpy(p, c_pop_host);
551
554 if (rc)
555 {
556 mutt_error(
_(
"%s is an invalid POP path"), c_pop_host);
557 return;
558 }
559
561 if (!conn)
562 return;
563
566
568 {
570 return;
571 }
572
574
575
578 if (rc == -1)
579 goto fail;
580 if (rc == -2)
581 {
583 goto finish;
584 }
585
586 sscanf(buf, "+OK %d %d", &msgs, &bytes);
587
588
590 if ((msgs > 0) && c_pop_last)
591 {
594 if (rc == -1)
595 goto fail;
596 if (rc == 0)
597 sscanf(buf, "+OK %d", &last);
598 }
599
600 if (msgs <= last)
601 {
603 goto finish;
604 }
605
608
610 {
612 goto finish;
613 }
614 bool old_append = m_spool->
append;
616
619
620 snprintf(msgbuf, sizeof(msgbuf),
621 ngettext("Reading new messages (%d byte)...",
622 "Reading new messages (%d bytes)...", bytes),
623 bytes);
625
626 for (int i = last + 1; i <= msgs; i++)
627 {
629 if (msg)
630 {
631 snprintf(buf, sizeof(buf), "RETR %d\r\n", i);
633 if (rc == -3)
634 rset = 1;
635
637 {
638 rset = 1;
639 rc = -3;
640 }
641
643 }
644 else
645 {
646 rc = -3;
647 }
648
649 if ((rc == 0) && (delanswer ==
MUTT_YES))
650 {
651
652 snprintf(buf, sizeof(buf), "DELE %d\r\n", i);
654 }
655
656 if (rc == -1)
657 {
658 m_spool->
append = old_append;
660 goto fail;
661 }
662 if (rc == -2)
663 {
665 break;
666 }
667 if (rc == -3)
668 {
670 break;
671 }
672
673
674
676 "%s [%d of %d messages read]", msgs - last),
677 msgbuf, i - last, msgs - last);
678 }
679
680 m_spool->
append = old_append;
682
683 if (rset)
684 {
685
687 if (
pop_query(adata, buf,
sizeof(buf)) == -1)
688 goto fail;
689 }
690
691finish:
692
694 if (
pop_query(adata, buf,
sizeof(buf)) == -1)
695 goto fail;
698 return;
699
700fail:
704}
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.