NeoMutt  2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
private.h File Reference

POP network mailbox. More...

#include <stdbool.h>
#include <time.h>
#include "conn/lib.h"
Include dependency graph for private.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PopCache
 POP-specific email cache. More...
struct  PopAuth
 POP authentication multiplexor. More...

Macros

#define POP_PORT   110
 Default port for POP3.
#define POP_SSL_PORT   995
 Default port for POP3 over SSL.
#define POP_CACHE_LEN   10
 Number of entries in the POP cache hash table.
#define POP_CMD_RESPONSE   512
 Maximum length of POP server response (per RFC1939).

Typedefs

typedef int(* pop_fetch_t) (const char *str, void *data)

Enumerations

enum  PopStatus { POP_NONE = 0 , POP_CONNECTED , POP_DISCONNECTED }
 POP server responses. More...
enum  PopAuthRes { POP_A_SUCCESS = 0 , POP_A_SOCKET , POP_A_FAILURE , POP_A_UNAVAIL }
 POP authentication responses. More...

Functions

bool pop_auth_is_valid (const char *authenticator)
 Check if string is a valid pop authentication method.
int pop_authenticate (struct PopAccountData *adata)
 Authenticate with a POP server.
void pop_apop_timestamp (struct PopAccountData *adata, char *buf)
 Get the server timestamp for APOP authentication.
int pop_parse_path (const char *path, struct ConnAccount *acct)
 Parse a POP mailbox name.
int pop_connect (struct PopAccountData *adata)
 Open connection.
int pop_open_connection (struct PopAccountData *adata)
 Open connection and authenticate.
int pop_query (struct PopAccountData *adata, char *buf, size_t buflen, char *msg)
 Send data from buffer and receive answer to the same buffer.
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_reconnect (struct Mailbox *m)
 Reconnect and verify indexes if connection was lost.
void pop_logout (struct Mailbox *m)
 Logout from a POP server.
const char * pop_get_field (enum ConnAccountField field, void *gf_data)
 Get connection login credentials - Implements ConnAccount::get_field() -.

Detailed Description

POP network mailbox.

Authors
  • Vsevolod Volkov
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file private.h.

Macro Definition Documentation

◆ POP_PORT

#define POP_PORT   110

Default port for POP3.

Definition at line 35 of file private.h.

◆ POP_SSL_PORT

#define POP_SSL_PORT   995

Default port for POP3 over SSL.

Definition at line 36 of file private.h.

◆ POP_CACHE_LEN

#define POP_CACHE_LEN   10

Number of entries in the POP cache hash table.

Definition at line 38 of file private.h.

◆ POP_CMD_RESPONSE

#define POP_CMD_RESPONSE   512

Maximum length of POP server response (per RFC1939).

Definition at line 40 of file private.h.

Typedef Documentation

◆ pop_fetch_t

typedef int(* pop_fetch_t) (const char *str, void *data)

Definition at line 106 of file private.h.

Enumeration Type Documentation

◆ PopStatus

enum PopStatus

POP server responses.

Enumerator
POP_NONE 

No connected to server.

POP_CONNECTED 

Connected to server.

POP_DISCONNECTED 

Disconnected from server.

Definition at line 45 of file private.h.

46{
47 POP_NONE = 0,
50};
@ POP_DISCONNECTED
Disconnected from server.
Definition private.h:49
@ POP_CONNECTED
Connected to server.
Definition private.h:48
@ POP_NONE
No connected to server.
Definition private.h:47

◆ PopAuthRes

enum PopAuthRes

POP authentication responses.

Enumerator
POP_A_SUCCESS 

Authenticated successfully.

POP_A_SOCKET 

Connection lost.

POP_A_FAILURE 

Authentication failed.

POP_A_UNAVAIL 

No valid authentication method.

Definition at line 55 of file private.h.

56{
57 POP_A_SUCCESS = 0,
61};
@ POP_A_UNAVAIL
No valid authentication method.
Definition private.h:60
@ POP_A_SUCCESS
Authenticated successfully.
Definition private.h:57
@ POP_A_FAILURE
Authentication failed.
Definition private.h:59
@ POP_A_SOCKET
Connection lost.
Definition private.h:58

Function Documentation

◆ pop_auth_is_valid()

bool pop_auth_is_valid ( const char * authenticator)

Check if string is a valid pop authentication method.

Parameters
authenticatorAuthenticator string to check
Return values
trueArgument is a valid auth method

Validate whether an input string is an accepted pop authentication method as defined by PopAuthenticators.

Definition at line 534 of file auth.c.

535{
536 for (size_t i = 0; i < countof(PopAuthenticators); i++)
537 {
538 const struct PopAuth *auth = &PopAuthenticators[i];
539 if (auth->method && mutt_istr_equal(auth->method, authenticator))
540 return true;
541 }
542
543 return false;
544}
#define countof(x)
Definition memory.h:49
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition string.c:678
static const struct PopAuth PopAuthenticators[]
Accepted authentication methods.
Definition auth.c:511
POP authentication multiplexor.
Definition private.h:76
const char * method
Name of authentication method supported, NULL means variable.
Definition private.h:87
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_authenticate()

int pop_authenticate ( struct PopAccountData * adata)

Authenticate with a POP server.

Parameters
adataPOP Account data
Return values
numResult, e.g. POP_A_SUCCESS
0Successful
-1Connection lost
-2Login failed
-3Authentication cancelled

Definition at line 555 of file auth.c.

556{
557 struct ConnAccount *cac = &adata->conn->account;
558 const struct PopAuth *authenticator = NULL;
559 int attempts = 0;
560 int rc = POP_A_UNAVAIL;
561
562 if ((mutt_account_getuser(cac) < 0) || (cac->user[0] == '\0'))
563 {
564 return -3;
565 }
566
567 const struct Slist *c_pop_authenticators = cs_subset_slist(NeoMutt->sub, "pop_authenticators");
568 const bool c_pop_auth_try_all = cs_subset_bool(NeoMutt->sub, "pop_auth_try_all");
569 if (c_pop_authenticators && (c_pop_authenticators->count > 0))
570 {
571 /* Try user-specified list of authentication methods */
572 struct ListNode *np = NULL;
573 STAILQ_FOREACH(np, &c_pop_authenticators->head, entries)
574 {
575 mutt_debug(LL_DEBUG2, "Trying method %s\n", np->data);
576 authenticator = PopAuthenticators;
577
578 /* Walk the built-in authenticator table looking for a match */
579 while (authenticator->authenticate)
580 {
581 if (!authenticator->method || mutt_istr_equal(authenticator->method, np->data))
582 {
583 rc = authenticator->authenticate(adata, np->data);
584 if (rc == POP_A_SOCKET)
585 {
586 /* Connection dropped; try reconnecting and retrying once */
587 switch (pop_connect(adata))
588 {
589 case 0:
590 {
591 rc = authenticator->authenticate(adata, np->data);
592 break;
593 }
594 case -2:
595 rc = POP_A_FAILURE;
596 break;
597 default:
598 break;
599 }
600 }
601
602 if (rc != POP_A_UNAVAIL)
603 attempts++;
604 if ((rc == POP_A_SUCCESS) || (rc == POP_A_SOCKET) ||
605 ((rc == POP_A_FAILURE) && !c_pop_auth_try_all))
606 {
607 break;
608 }
609 }
610 authenticator++;
611 }
612 }
613 }
614 else
615 {
616 /* Fall back to default: try every authenticator in order */
617 mutt_debug(LL_DEBUG2, "Using any available method\n");
618 authenticator = PopAuthenticators;
619
620 while (authenticator->authenticate)
621 {
622 rc = authenticator->authenticate(adata, NULL);
623 if (rc == POP_A_SOCKET)
624 {
625 switch (pop_connect(adata))
626 {
627 case 0:
628 {
629 rc = authenticator->authenticate(adata, NULL);
630 break;
631 }
632 case -2:
633 rc = POP_A_FAILURE;
634 break;
635 default:
636 break;
637 }
638 }
639
640 if (rc != POP_A_UNAVAIL)
641 attempts++;
642 if ((rc == POP_A_SUCCESS) || (rc == POP_A_SOCKET) ||
643 ((rc == POP_A_FAILURE) && !c_pop_auth_try_all))
644 {
645 break;
646 }
647
648 authenticator++;
649 }
650 }
651
652 /* Map internal result code to the caller's return values */
653 switch (rc)
654 {
655 case POP_A_SUCCESS:
656 return 0;
657 case POP_A_SOCKET:
658 return -1;
659 case POP_A_UNAVAIL:
660 if (attempts == 0)
661 mutt_error(_("No authenticators available"));
662 break;
663
664 default:
665 break;
666 }
667
668 return -2;
669}
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition helpers.c:242
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
int mutt_account_getuser(struct ConnAccount *cac)
Retrieve username into ConnAccount, if necessary.
Definition connaccount.c:51
#define mutt_error(...)
Definition logging2.h:94
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG2
Log at debug level 2.
Definition logging2.h:46
#define _(a)
Definition message.h:28
int pop_connect(struct PopAccountData *adata)
Open connection.
Definition lib.c:282
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
Login details for a remote server.
Definition connaccount.h:59
char user[128]
Username.
Definition connaccount.h:62
struct ConnAccount account
Account details: username, password, etc.
Definition connection.h:49
A List node for strings.
Definition list.h:37
char * data
String.
Definition list.h:38
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
struct Connection * conn
Connection to POP server.
Definition adata.h:38
enum PopAuthRes(* authenticate)(struct PopAccountData *adata, const char *method)
Definition private.h:85
String list.
Definition slist.h:37
struct ListHead head
List containing values.
Definition slist.h:38
size_t count
Number of values in list.
Definition slist.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_apop_timestamp()

void pop_apop_timestamp ( struct PopAccountData * adata,
char * buf )

Get the server timestamp for APOP authentication.

Parameters
adataPOP Account data
bufTimestamp string

Definition at line 326 of file auth.c.

327{
328 char *p1 = NULL;
329 char *p2 = NULL;
330
331 FREE(&adata->timestamp);
332
333 if ((p1 = strchr(buf, '<')) && (p2 = strchr(p1, '>')))
334 {
335 p2[1] = '\0';
336 adata->timestamp = mutt_str_dup(p1);
337 }
338}
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
char * timestamp
APOP timestamp.
Definition adata.h:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_parse_path()

int pop_parse_path ( const char * path,
struct ConnAccount * cac )

Parse a POP mailbox name.

Parameters
pathPath to parse
cacAccount to store details
Return values
0success
-1error

Split a POP path into host, port, username and password

Definition at line 82 of file lib.c.

83{
84 /* Defaults */
85 cac->flags = 0;
87 cac->port = 0;
88 cac->service = "pop";
90
91 struct Url *url = url_parse(path);
92
93 if (!url || ((url->scheme != U_POP) && (url->scheme != U_POPS)) ||
94 !url->host || (account_from_url(cac, url) < 0))
95 {
96 url_free(&url);
97 mutt_error(_("Invalid POP URL: %s"), path);
98 return -1;
99 }
100
101 if (url->scheme == U_POPS)
102 cac->flags |= MUTT_ACCT_SSL;
103
104 struct servent *service = getservbyname((url->scheme == U_POP) ? "pop3" : "pop3s", "tcp");
105 if (cac->port == 0)
106 {
107 if (service)
108 cac->port = ntohs(service->s_port);
109 else
110 cac->port = (url->scheme == U_POP) ? POP_PORT : POP_SSL_PORT;
111 }
112
113 url_free(&url);
114 return 0;
115}
@ MUTT_ACCT_SSL
Account uses SSL/TLS.
Definition connaccount.h:51
const char * pop_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field() -.
Definition lib.c:56
int account_from_url(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
@ MUTT_ACCT_TYPE_POP
Pop Account.
#define POP_SSL_PORT
Default port for POP3 over SSL.
Definition private.h:36
#define POP_PORT
Default port for POP3.
Definition private.h:35
const char * service
Name of the service, e.g. "imap".
Definition connaccount.h:67
const char *(* get_field)(enum ConnAccountField field, void *gf_data)
Definition connaccount.h:76
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
Definition connaccount.h:65
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition connaccount.h:66
unsigned short port
Port to connect to.
Definition connaccount.h:64
A parsed URL proto://user:password@host:port/path?a=1&b=2.
Definition url.h:69
char * host
Host.
Definition url.h:73
char * path
Path.
Definition url.h:75
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
Definition url.h:70
struct Url * url_parse(const char *src)
Fill in Url.
Definition url.c:242
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition url.c:124
@ U_POPS
Url is pops://.
Definition url.h:38
@ U_POP
Url is pop://.
Definition url.h:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_connect()

int pop_connect ( struct PopAccountData * adata)

Open connection.

Parameters
adataPOP Account data
Return values
0Successful
-1Connection lost
-2Invalid response

Definition at line 282 of file lib.c.

283{
284 char buf[1024] = { 0 };
285
286 adata->status = POP_NONE;
287 if ((mutt_socket_open(adata->conn) < 0) ||
288 (mutt_socket_readln(buf, sizeof(buf), adata->conn) < 0))
289 {
290 mutt_error(_("Error connecting to server: %s"), adata->conn->account.host);
291 return -1;
292 }
293
294 adata->status = POP_CONNECTED;
295
296 if (!mutt_str_startswith(buf, "+OK"))
297 {
298 *adata->err_msg = '\0';
299 pop_error(adata, buf);
300 mutt_error("%s", adata->err_msg);
301 return -2;
302 }
303
304 pop_apop_timestamp(adata, buf);
305
306 return 0;
307}
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition string.c:234
void pop_apop_timestamp(struct PopAccountData *adata, char *buf)
Get the server timestamp for APOP authentication.
Definition auth.c:326
static void pop_error(struct PopAccountData *adata, char *msg)
Copy error message to err_msg buffer.
Definition lib.c:122
int mutt_socket_open(struct Connection *conn)
Simple wrapper.
Definition socket.c:76
#define mutt_socket_readln(buf, buflen, conn)
Definition socket.h:55
char host[128]
Server to login to.
Definition connaccount.h:60
char err_msg[POP_CMD_RESPONSE]
Last error message.
Definition adata.h:57
unsigned int status
Connection status.
Definition adata.h:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_open_connection()

int pop_open_connection ( struct PopAccountData * adata)

Open connection and authenticate.

Parameters
adataPOP Account data
Return values
0Successful
-1Connection lost
-2Invalid command or execution error
-3Authentication cancelled

Definition at line 317 of file lib.c.

318{
319 char buf[1024] = { 0 };
320
321 int rc = pop_connect(adata);
322 if (rc < 0)
323 return rc;
324
325 rc = pop_capabilities(adata, 0);
326 if (rc == -1)
327 goto err_conn;
328 if (rc == -2)
329 return -2;
330
331#ifdef USE_SSL
332 /* Attempt STLS if available and desired. */
333 const bool c_ssl_force_tls = cs_subset_bool(NeoMutt->sub, "ssl_force_tls");
334 if ((adata->conn->ssf == 0) && (adata->cmd_stls || c_ssl_force_tls))
335 {
336 if (c_ssl_force_tls)
337 adata->use_stls = 2;
338 if (adata->use_stls == 0)
339 {
340 enum QuadOption ans = query_quadoption(_("Secure connection with TLS?"),
341 NeoMutt->sub, "ssl_starttls");
342 if (ans == MUTT_ABORT)
343 return -2;
344 adata->use_stls = 1;
345 if (ans == MUTT_YES)
346 adata->use_stls = 2;
347 }
348 if (adata->use_stls == 2)
349 {
350 mutt_str_copy(buf, "STLS\r\n", sizeof(buf));
351 rc = pop_query(adata, buf, sizeof(buf), NULL);
352 // Clear any data after the STLS acknowledgement
353 mutt_socket_empty(adata->conn);
354 if (rc == -1)
355 goto err_conn;
356 if (rc != 0)
357 {
358 mutt_error("%s", adata->err_msg);
359 }
360 else if (mutt_ssl_starttls(adata->conn) != 0)
361 {
362 mutt_error(_("Could not negotiate TLS connection"));
363 return -2;
364 }
365 else
366 {
367 /* recheck capabilities after STLS completes */
368 rc = pop_capabilities(adata, 1);
369 if (rc == -1)
370 goto err_conn;
371 if (rc == -2)
372 return -2;
373 }
374 }
375 }
376
377 if (c_ssl_force_tls && (adata->conn->ssf == 0))
378 {
379 mutt_error(_("Encrypted connection unavailable"));
380 return -2;
381 }
382#endif
383
384 rc = pop_authenticate(adata);
385 if (rc == -1)
386 goto err_conn;
387 if (rc == -3)
389 if (rc != 0)
390 return rc;
391
392 /* recheck capabilities after authentication */
393 rc = pop_capabilities(adata, 2);
394 if (rc == -1)
395 goto err_conn;
396 if (rc == -2)
397 return -2;
398
399 /* get total size of mailbox */
400 mutt_str_copy(buf, "STAT\r\n", sizeof(buf));
401 rc = pop_query(adata, buf, sizeof(buf), NULL);
402 if (rc == -1)
403 goto err_conn;
404 if (rc == -2)
405 {
406 mutt_error("%s", adata->err_msg);
407 return rc;
408 }
409
410 unsigned int n = 0;
411 size_t size = 0;
412 sscanf(buf, "+OK %u %zu", &n, &size);
413 adata->size = size;
414 return 0;
415
416err_conn:
417 adata->status = POP_DISCONNECTED;
418 mutt_error(_("Server closed connection"));
419 return -1;
420}
int mutt_ssl_starttls(struct Connection *conn)
Negotiate TLS over an already opened connection.
Definition gnutls.c:1176
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination).
Definition string.c:587
void mutt_clear_error(void)
Clear the message line (bottom line of screen).
int pop_authenticate(struct PopAccountData *adata)
Authenticate with a POP server.
Definition auth.c:555
static int pop_capabilities(struct PopAccountData *adata, int mode)
Get capabilities from a POP server.
Definition lib.c:202
int pop_query(struct PopAccountData *adata, char *buf, size_t buflen, char *msg)
Send data from buffer and receive answer to the same buffer.
Definition lib.c:467
QuadOption
Possible values for a quad-option.
Definition quad.h:36
@ MUTT_ABORT
User aborted the question (with Ctrl-G).
Definition quad.h:37
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition quad.h:39
enum QuadOption query_quadoption(const char *prompt, struct ConfigSubset *sub, const char *name)
Ask the user a quad-question.
Definition question.c:384
void mutt_socket_empty(struct Connection *conn)
Clear out any queued data.
Definition socket.c:306
unsigned int ssf
Security strength factor, in bits (see notes).
Definition connection.h:50
size_t size
Mailbox size.
Definition adata.h:50
bool cmd_stls
optional command STLS
Definition adata.h:43
unsigned int use_stls
Use STLS.
Definition adata.h:41
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_query()

int pop_query ( struct PopAccountData * adata,
char * buf,
size_t buflen,
char * msg )

Send data from buffer and receive answer to the same buffer.

Parameters
adataPOP Account data
bufBuffer to send/store data
buflenBuffer length
msgProgress message
Return values
0Successful
-1Connection lost
-2Invalid command or execution error

Definition at line 467 of file lib.c.

468{
469 if (adata->status != POP_CONNECTED)
470 return -1;
471
472 /* print msg instead of real command */
473 if (msg)
474 {
475 mutt_debug(MUTT_SOCK_LOG_CMD, "> %s", msg);
476 }
477
479
480 char *c = strpbrk(buf, " \r\n");
481 if (c)
482 *c = '\0';
483 snprintf(adata->err_msg, sizeof(adata->err_msg), "%s: ", buf);
484
485 if (mutt_socket_readln_d(buf, buflen, adata->conn, MUTT_SOCK_LOG_FULL) < 0)
486 {
487 adata->status = POP_DISCONNECTED;
488 return -1;
489 }
490 if (mutt_str_startswith(buf, "+OK"))
491 return 0;
492
493 pop_error(adata, buf);
494 return -2;
495}
int mutt_socket_readln_d(char *buf, size_t buflen, struct Connection *conn, int dbg)
Read a line from a socket.
Definition socket.c:238
#define MUTT_SOCK_LOG_FULL
Log everything including full protocol.
Definition socket.h:53
#define MUTT_SOCK_LOG_CMD
Log commands only.
Definition socket.h:51
#define mutt_socket_send_d(conn, buf, dbg)
Definition socket.h:57
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_fetch_data()

int pop_fetch_data ( struct PopAccountData * adata,
const char * query,
struct Progress * progress,
pop_fetch_t callback,
void * data )

Read Headers with callback function.

Parameters
adataPOP Account data
queryPOP query to send to server
progressProgress bar
callbackFunction called for each header read
dataData to pass to the callback
Return values
0Successful
-1Connection lost
-2Invalid command or execution error
-3Error in callback(*line, *data)

This function calls callback(*line, *data) for each received line, callback(NULL, *data) if rewind(*data) needs, exits when fail or done.

Definition at line 512 of file lib.c.

514{
515 char buf[1024] = { 0 };
516 long pos = 0;
517 size_t lenbuf = 0;
518
519 mutt_str_copy(buf, query, sizeof(buf));
520 int rc = pop_query(adata, buf, sizeof(buf), NULL);
521 if (rc < 0)
522 return rc;
523
524 char *inbuf = MUTT_MEM_MALLOC(sizeof(buf), char);
525
526 while (true)
527 {
528 const int chunk = mutt_socket_readln_d(buf, sizeof(buf), adata->conn, MUTT_SOCK_LOG_FULL);
529 if (chunk < 0)
530 {
531 adata->status = POP_DISCONNECTED;
532 rc = -1;
533 break;
534 }
535
536 char *p = buf;
537 if (!lenbuf && (buf[0] == '.'))
538 {
539 if (buf[1] != '.')
540 break;
541 p++;
542 }
543
544 mutt_str_copy(inbuf + lenbuf, p, sizeof(buf));
545 pos += chunk;
546
547 /* cast is safe since we break out of the loop when chunk<=0 */
548 if ((size_t) chunk >= sizeof(buf))
549 {
550 lenbuf += strlen(p);
551 }
552 else
553 {
554 progress_update(progress, pos, -1);
555 if ((rc == 0) && (callback(inbuf, data) < 0))
556 rc = -3;
557 lenbuf = 0;
558 }
559
560 MUTT_MEM_REALLOC(&inbuf, lenbuf + sizeof(buf), char);
561 }
562
563 FREE(&inbuf);
564 return rc;
565}
#define MUTT_MEM_REALLOC(pptr, n, type)
Definition memory.h:55
#define MUTT_MEM_MALLOC(n, type)
Definition memory.h:53
bool progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
Definition progress.c:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_reconnect()

int pop_reconnect ( struct Mailbox * m)

Reconnect and verify indexes if connection was lost.

Parameters
mMailbox
Return values
0Success
-1Error

Definition at line 610 of file lib.c.

611{
613
614 if (adata->status == POP_CONNECTED)
615 return 0;
616
617 while (true)
618 {
620
621 int rc = pop_open_connection(adata);
622 if (rc == 0)
623 {
624 struct Progress *progress = progress_new(MUTT_PROGRESS_NET, 0);
625 progress_set_message(progress, _("Verifying message indexes..."));
626
627 for (int i = 0; i < m->msg_count; i++)
628 {
629 struct PopEmailData *edata = pop_edata_get(m->emails[i]);
630 edata->refno = -1;
631 }
632
633 rc = pop_fetch_data(adata, "UIDL\r\n", progress, check_uidl, m);
634 progress_free(&progress);
635 if (rc == -2)
636 {
637 mutt_error("%s", adata->err_msg);
638 }
639 }
640
641 if (rc == 0)
642 return 0;
643
644 pop_logout(m);
645
646 if (rc < -1)
647 return -1;
648
649 if (query_quadoption(_("Connection lost. Reconnect to POP server?"),
650 NeoMutt->sub, "pop_reconnect") != MUTT_YES)
651 {
652 return -1;
653 }
654 }
655}
static int check_uidl(const char *line, void *data)
Parse UIDL response - Implements pop_fetch_t -.
Definition lib.c:576
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition adata.c:73
struct PopEmailData * pop_edata_get(struct Email *e)
Get the private data for this Email.
Definition edata.c:68
int pop_open_connection(struct PopAccountData *adata)
Open connection and authenticate.
Definition lib.c:317
int pop_fetch_data(struct PopAccountData *adata, const char *query, struct Progress *progress, pop_fetch_t callback, void *data)
Read Headers with callback function.
Definition lib.c:512
void pop_logout(struct Mailbox *m)
Logout from a POP server.
Definition lib.c:426
@ MUTT_PROGRESS_NET
Progress tracks bytes, according to $net_inc.
Definition lib.h:83
struct Progress * progress_new(enum ProgressType type, size_t size)
Create a new Progress Bar.
Definition progress.c:139
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition progress.c:110
void progress_set_message(struct Progress *progress, const char *fmt,...) __attribute__((__format__(__printf__
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition socket.c:100
void * adata
Private data (for Mailbox backends).
Definition account.h:42
void * edata
Driver-specific data.
Definition email.h:74
int msg_count
Total number of messages.
Definition mailbox.h:90
struct Email ** emails
Array of Emails.
Definition mailbox.h:98
POP-specific Account data -.
Definition adata.h:37
POP-specific Email data -.
Definition edata.h:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pop_logout()

void pop_logout ( struct Mailbox * m)

Logout from a POP server.

Parameters
mMailbox

Definition at line 426 of file lib.c.

427{
429
430 if (adata->status == POP_CONNECTED)
431 {
432 int rc = 0;
433 char buf[1024] = { 0 };
434 mutt_message(_("Closing connection to POP server..."));
435
436 if (m->readonly)
437 {
438 mutt_str_copy(buf, "RSET\r\n", sizeof(buf));
439 rc = pop_query(adata, buf, sizeof(buf), NULL);
440 }
441
442 if (rc != -1)
443 {
444 mutt_str_copy(buf, "QUIT\r\n", sizeof(buf));
445 rc = pop_query(adata, buf, sizeof(buf), NULL);
446 }
447
448 if (rc < 0)
449 mutt_debug(LL_DEBUG1, "Error closing POP connection\n");
450
452 }
453
454 adata->status = POP_DISCONNECTED;
455}
#define mutt_message(...)
Definition logging2.h:93
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
bool readonly
Don't allow changes to the mailbox.
Definition mailbox.h:118
Here is the call graph for this function:
Here is the caller graph for this function: