Fetch messages and save them in $spool_file.
511{
513 if (!c_pop_host)
514 {
516 return;
517 }
518
519 char buf[1024] = { 0 };
520 char msgbuf[128] = { 0 };
521 int last = 0, msgs, bytes, rset = 0, rc;
523
525 char *url = p;
527 {
528 strcpy(url, "pop://");
529 p = strchr(url, '\0');
530 }
531 strcpy(p, c_pop_host);
532
535 if (rc)
536 {
537 mutt_error(
_(
"%s is an invalid POP path"), c_pop_host);
538 return;
539 }
540
542 if (!conn)
543 return;
544
547
549 {
550
552 return;
553 }
554
556
557
560 if (rc == -1)
561 goto fail;
562 if (rc == -2)
563 {
565 goto finish;
566 }
567
568 sscanf(buf, "+OK %d %d", &msgs, &bytes);
569
570
572 if ((msgs > 0) && c_pop_last)
573 {
576 if (rc == -1)
577 goto fail;
578 if (rc == 0)
579 sscanf(buf, "+OK %d", &last);
580 }
581
582 if (msgs <= last)
583 {
585 goto finish;
586 }
587
590
592 {
594 goto finish;
595 }
596 bool old_append = m_spool->
append;
598
601
602 snprintf(msgbuf, sizeof(msgbuf),
603 ngettext("Reading new messages (%d byte)...",
604 "Reading new messages (%d bytes)...", bytes),
605 bytes);
607
608 for (int i = last + 1; i <= msgs; i++)
609 {
611 if (msg)
612 {
613 snprintf(buf, sizeof(buf), "RETR %d\r\n", i);
615 if (rc == -3)
616 rset = 1;
617
619 {
620 rset = 1;
621 rc = -3;
622 }
623
625 }
626 else
627 {
628 rc = -3;
629 }
630
631 if ((rc == 0) && (delanswer ==
MUTT_YES))
632 {
633
634 snprintf(buf, sizeof(buf), "DELE %d\r\n", i);
636 }
637
638 if (rc == -1)
639 {
640 m_spool->
append = old_append;
642 goto fail;
643 }
644 if (rc == -2)
645 {
647 break;
648 }
649 if (rc == -3)
650 {
652 break;
653 }
654
655
656
658 "%s [%d of %d messages read]", msgs - last),
659 msgbuf, i - last, msgs - last);
660 }
661
662 m_spool->
append = old_append;
664
665 if (rset)
666 {
667
669 if (
pop_query(adata, buf,
sizeof(buf)) == -1)
670 goto fail;
671 }
672
673finish:
674
676 if (
pop_query(adata, buf,
sizeof(buf)) == -1)
677 goto fail;
680 return;
681
682fail:
686}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
#define mutt_message(...)
static int fetch_message(const char *line, void *data)
Write line to file - Implements pop_fetch_t -.
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
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 **msg)
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.
void pop_adata_free(void **ptr)
Free the private Account data - Implements Account::adata_free()
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.
#define pop_query(adata, buf, buflen)
QuadOption
Possible values for a quad-option.
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
enum QuadOption query_quadoption(enum QuadOption opt, const char *prompt)
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]
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.