Fetch messages and save them in $spool_file.
534{
536 if (!c_pop_host)
537 {
539 return;
540 }
541
542 char buf[1024] = { 0 };
543 char msgbuf[128] = { 0 };
544 int last = 0;
545 int msgs = 0;
546 int bytes = 0;
547 int rset = 0;
548 int rc;
550
551 char *url = NULL;
554 else
556
559 if (rc)
560 {
561 mutt_error(
_(
"%s is an invalid POP path"), c_pop_host);
562 return;
563 }
564
566 if (!conn)
567 return;
568
571
573 {
575 return;
576 }
577
579
580
583 if (rc == -1)
584 goto fail;
585 if (rc == -2)
586 {
588 goto finish;
589 }
590
591 sscanf(buf, "+OK %d %d", &msgs, &bytes);
592
593
595 if ((msgs > 0) && c_pop_last)
596 {
599 if (rc == -1)
600 goto fail;
601 if (rc == 0)
602 sscanf(buf, "+OK %d", &last);
603 }
604
605 if (msgs <= last)
606 {
608 goto finish;
609 }
610
613
615 {
617 goto finish;
618 }
619 bool old_append = m_spool->
append;
621
624
625 snprintf(msgbuf, sizeof(msgbuf),
626 ngettext("Reading new messages (%d byte)...",
627 "Reading new messages (%d bytes)...", bytes),
628 bytes);
630
631 for (int i = last + 1; i <= msgs; i++)
632 {
634 if (msg)
635 {
636 snprintf(buf, sizeof(buf), "RETR %d\r\n", i);
638 if (rc == -3)
639 rset = 1;
640
642 {
643 rset = 1;
644 rc = -3;
645 }
646
648 }
649 else
650 {
651 rc = -3;
652 }
653
654 if ((rc == 0) && (delanswer ==
MUTT_YES))
655 {
656
657 snprintf(buf, sizeof(buf), "DELE %d\r\n", i);
658 rc =
pop_query(adata, buf,
sizeof(buf), NULL);
659 }
660
661 if (rc == -1)
662 {
663 m_spool->
append = old_append;
665 goto fail;
666 }
667 if (rc == -2)
668 {
670 break;
671 }
672 if (rc == -3)
673 {
675 break;
676 }
677
678
679
681 "%s [%d of %d messages read]", msgs - last),
682 msgbuf, i - last, msgs - last);
683 }
684
685 m_spool->
append = old_append;
687
688 if (rset)
689 {
690
692 if (
pop_query(adata, buf,
sizeof(buf), NULL) == -1)
693 goto fail;
694 }
695
696finish:
697
699 if (
pop_query(adata, buf,
sizeof(buf), NULL) == -1)
700 goto fail;
703 return;
704
705fail:
709}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean 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(...)
static int fetch_message(const char *line, void *data)
Parse a Message response - Implements pop_fetch_t -.
#define FREE(x)
Free memory and set the pointer to NULL.
char * mutt_str_dup(const char *str)
Copy a string, safely.
int mutt_str_asprintf(char **strp, const char *fmt,...)
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination).
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.
@ MUTT_ADD_FROM
add a From_ line
@ MUTT_OPEN_NONE
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.
int pop_fetch_data(struct PopAccountData *adata, const char *query, struct Progress *progress, pop_fetch_t callback, void *data)
Read Headers with callback function.
int pop_query(struct PopAccountData *adata, char *buf, size_t buflen, char *msg)
Send data from buffer and receive answer to the same buffer.
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.
void * adata
Private data (for Mailbox backends).
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
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.
POP-specific Account data -.
char err_msg[POP_CMD_RESPONSE]
Last error message.
struct Connection * conn
Connection to POP server.
enum UrlScheme url_check_scheme(const char *str)
Check the protocol of a URL.
@ U_UNKNOWN
Url wasn't recognised.