NeoMutt  2022-04-29-178-g3b62e6
Teaching an old dog new tricks
DOXYGEN
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
 
#define POP_SSL_PORT   995
 
#define POP_CACHE_LEN   10
 
#define POP_CMD_RESPONSE   512
 
#define pop_query(adata, buf, buflen)   pop_query_d(adata, buf, buflen, NULL)
 

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. More...
 
int pop_authenticate (struct PopAccountData *adata)
 Authenticate with a POP server. More...
 
void pop_apop_timestamp (struct PopAccountData *adata, char *buf)
 Get the server timestamp for APOP authentication. More...
 
int pop_parse_path (const char *path, struct ConnAccount *acct)
 Parse a POP mailbox name. More...
 
int pop_connect (struct PopAccountData *adata)
 Open connection. More...
 
int pop_open_connection (struct PopAccountData *adata)
 Open connection and authenticate. More...
 
int pop_query_d (struct PopAccountData *adata, char *buf, size_t buflen, char *msg)
 Send data from buffer and receive answer to the same buffer. More...
 
int pop_fetch_data (struct PopAccountData *adata, const char *query, struct Progress *progress, pop_fetch_t callback, void *data)
 Read Headers with callback function. More...
 
int pop_reconnect (struct Mailbox *m)
 Reconnect and verify indexes if connection was lost. More...
 
void pop_logout (struct Mailbox *m)
 Logout from a POP server. More...
 
const char * pop_get_field (enum ConnAccountField field, void *gf_data)
 Get connection login credentials - Implements ConnAccount::get_field() More...
 

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

Definition at line 35 of file private.h.

◆ POP_SSL_PORT

#define POP_SSL_PORT   995

Definition at line 36 of file private.h.

◆ POP_CACHE_LEN

#define POP_CACHE_LEN   10

Definition at line 39 of file private.h.

◆ POP_CMD_RESPONSE

#define POP_CMD_RESPONSE   512

Definition at line 42 of file private.h.

◆ pop_query

#define pop_query (   adata,
  buf,
  buflen 
)    pop_query_d(adata, buf, buflen, NULL)

Definition at line 109 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 47 of file private.h.

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

◆ 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 57 of file private.h.

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

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 403 of file auth.c.

404{
405 for (size_t i = 0; i < mutt_array_size(PopAuthenticators); i++)
406 {
407 const struct PopAuth *auth = &PopAuthenticators[i];
408 if (auth->method && mutt_istr_equal(auth->method, authenticator))
409 return true;
410 }
411
412 return false;
413}
#define mutt_array_size(x)
Definition: memory.h:36
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:796
static const struct PopAuth PopAuthenticators[]
Accepted authentication methods.
Definition: auth.c:383
POP authentication multiplexor.
Definition: private.h:78
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 424 of file auth.c.

425{
426 struct ConnAccount *cac = &adata->conn->account;
427 const struct PopAuth *authenticator = NULL;
428 int attempts = 0;
429 int rc = POP_A_UNAVAIL;
430
431 if ((mutt_account_getuser(cac) < 0) || (cac->user[0] == '\0'))
432 {
433 return -3;
434 }
435
436 const struct Slist *c_pop_authenticators = cs_subset_slist(NeoMutt->sub, "pop_authenticators");
437 const bool c_pop_auth_try_all = cs_subset_bool(NeoMutt->sub, "pop_auth_try_all");
438 if (c_pop_authenticators && (c_pop_authenticators->count > 0))
439 {
440 /* Try user-specified list of authentication methods */
441 struct ListNode *np = NULL;
442 STAILQ_FOREACH(np, &c_pop_authenticators->head, entries)
443 {
444 mutt_debug(LL_DEBUG2, "Trying method %s\n", np->data);
445 authenticator = PopAuthenticators;
446
447 while (authenticator->authenticate)
448 {
449 if (!authenticator->method || mutt_istr_equal(authenticator->method, np->data))
450 {
451 rc = authenticator->authenticate(adata, np->data);
452 if (rc == POP_A_SOCKET)
453 {
454 switch (pop_connect(adata))
455 {
456 case 0:
457 {
458 rc = authenticator->authenticate(adata, np->data);
459 break;
460 }
461 case -2:
462 rc = POP_A_FAILURE;
463 }
464 }
465
466 if (rc != POP_A_UNAVAIL)
467 attempts++;
468 if ((rc == POP_A_SUCCESS) || (rc == POP_A_SOCKET) ||
469 ((rc == POP_A_FAILURE) && !c_pop_auth_try_all))
470 {
471 break;
472 }
473 }
474 authenticator++;
475 }
476 }
477 }
478 else
479 {
480 /* Fall back to default: any authenticator */
481 mutt_debug(LL_DEBUG2, "Using any available method\n");
482 authenticator = PopAuthenticators;
483
484 while (authenticator->authenticate)
485 {
486 rc = authenticator->authenticate(adata, NULL);
487 if (rc == POP_A_SOCKET)
488 {
489 switch (pop_connect(adata))
490 {
491 case 0:
492 {
493 rc = authenticator->authenticate(adata, NULL);
494 break;
495 }
496 case -2:
497 rc = POP_A_FAILURE;
498 }
499 }
500
501 if (rc != POP_A_UNAVAIL)
502 attempts++;
503 if ((rc == POP_A_SUCCESS) || (rc == POP_A_SOCKET) ||
504 ((rc == POP_A_FAILURE) && !c_pop_auth_try_all))
505 {
506 break;
507 }
508
509 authenticator++;
510 }
511 }
512
513 switch (rc)
514 {
515 case POP_A_SUCCESS:
516 return 0;
517 case POP_A_SOCKET:
518 return -1;
519 case POP_A_UNAVAIL:
520 if (attempts == 0)
521 mutt_error(_("No authenticators available"));
522 }
523
524 return -2;
525}
const struct Slist * cs_subset_slist(const struct ConfigSubset *sub, const char *name)
Get a string-list config item by name.
Definition: helpers.c:268
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
int mutt_account_getuser(struct ConnAccount *cac)
Retrieve username into ConnAccount, if necessary.
Definition: connaccount.c:50
#define mutt_error(...)
Definition: logging.h:87
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
#define _(a)
Definition: message.h:28
int pop_connect(struct PopAccountData *adata)
Open connection.
Definition: lib.c:273
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
Login details for a remote server.
Definition: connaccount.h:53
char user[128]
Username.
Definition: connaccount.h:56
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:50
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
struct Connection * conn
Connection to POP server.
Definition: adata.h:38
enum PopAuthRes(* authenticate)(struct PopAccountData *adata, const char *method)
Authenticate a POP connection.
Definition: private.h:85
String list.
Definition: slist.h:47
struct ListHead head
List containing values.
Definition: slist.h:48
size_t count
Number of values in list.
Definition: slist.h:49
+ 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 204 of file auth.c.

205{
206 char *p1 = NULL, *p2 = NULL;
207
208 FREE(&adata->timestamp);
209
210 if ((p1 = strchr(buf, '<')) && (p2 = strchr(p1, '>')))
211 {
212 p2[1] = '\0';
213 adata->timestamp = mutt_str_dup(p1);
214 }
215}
#define FREE(x)
Definition: memory.h:43
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
char * timestamp
Definition: adata.h:54
+ 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 || (mutt_account_fromurl(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}
#define MUTT_ACCT_SSL
Account uses SSL/TLS.
Definition: connaccount.h:47
int mutt_account_fromurl(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
Definition: mutt_account.c:43
@ MUTT_ACCT_TYPE_POP
Pop Account.
Definition: mutt_account.h:38
const char * pop_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field()
Definition: lib.c:56
#define POP_SSL_PORT
Definition: private.h:36
#define POP_PORT
Definition: private.h:35
const char * service
Name of the service, e.g. "imap".
Definition: connaccount.h:61
const char *(* get_field)(enum ConnAccountField field, void *gf_data)
Function to get some login credentials.
Definition: connaccount.h:68
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
Definition: connaccount.h:59
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition: connaccount.h:60
unsigned short port
Port to connect to.
Definition: connaccount.h:58
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:234
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition: url.c:123
@ 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 273 of file lib.c.

274{
275 char buf[1024] = { 0 };
276
277 adata->status = POP_NONE;
278 if ((mutt_socket_open(adata->conn) < 0) ||
279 (mutt_socket_readln(buf, sizeof(buf), adata->conn) < 0))
280 {
281 mutt_error(_("Error connecting to server: %s"), adata->conn->account.host);
282 return -1;
283 }
284
285 adata->status = POP_CONNECTED;
286
287 if (!mutt_str_startswith(buf, "+OK"))
288 {
289 *adata->err_msg = '\0';
290 pop_error(adata, buf);
291 mutt_error("%s", adata->err_msg);
292 return -2;
293 }
294
295 pop_apop_timestamp(adata, buf);
296
297 return 0;
298}
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
Definition: string.c:227
void pop_apop_timestamp(struct PopAccountData *adata, char *buf)
Get the server timestamp for APOP authentication.
Definition: auth.c:204
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:57
char host[128]
Server to login to.
Definition: connaccount.h:54
char err_msg[POP_CMD_RESPONSE]
Definition: adata.h:56
unsigned int 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 308 of file lib.c.

309{
310 char buf[1024] = { 0 };
311
312 int rc = pop_connect(adata);
313 if (rc < 0)
314 return rc;
315
316 rc = pop_capabilities(adata, 0);
317 if (rc == -1)
318 goto err_conn;
319 if (rc == -2)
320 return -2;
321
322#ifdef USE_SSL
323 /* Attempt STLS if available and desired. */
324 const bool c_ssl_force_tls = cs_subset_bool(NeoMutt->sub, "ssl_force_tls");
325 if ((adata->conn->ssf == 0) && (adata->cmd_stls || c_ssl_force_tls))
326 {
327 if (c_ssl_force_tls)
328 adata->use_stls = 2;
329 if (adata->use_stls == 0)
330 {
331 const enum QuadOption c_ssl_starttls = cs_subset_quad(NeoMutt->sub, "ssl_starttls");
332 enum QuadOption ans = query_quadoption(c_ssl_starttls, _("Secure connection with TLS?"));
333 if (ans == MUTT_ABORT)
334 return -2;
335 adata->use_stls = 1;
336 if (ans == MUTT_YES)
337 adata->use_stls = 2;
338 }
339 if (adata->use_stls == 2)
340 {
341 mutt_str_copy(buf, "STLS\r\n", sizeof(buf));
342 rc = pop_query(adata, buf, sizeof(buf));
343 // Clear any data after the STLS acknowledgement
344 mutt_socket_empty(adata->conn);
345 if (rc == -1)
346 goto err_conn;
347 if (rc != 0)
348 {
349 mutt_error("%s", adata->err_msg);
350 }
351 else if (mutt_ssl_starttls(adata->conn))
352 {
353 mutt_error(_("Could not negotiate TLS connection"));
354 return -2;
355 }
356 else
357 {
358 /* recheck capabilities after STLS completes */
359 rc = pop_capabilities(adata, 1);
360 if (rc == -1)
361 goto err_conn;
362 if (rc == -2)
363 return -2;
364 }
365 }
366 }
367
368 if (c_ssl_force_tls && (adata->conn->ssf == 0))
369 {
370 mutt_error(_("Encrypted connection unavailable"));
371 return -2;
372 }
373#endif
374
375 rc = pop_authenticate(adata);
376 if (rc == -1)
377 goto err_conn;
378 if (rc == -3)
380 if (rc != 0)
381 return rc;
382
383 /* recheck capabilities after authentication */
384 rc = pop_capabilities(adata, 2);
385 if (rc == -1)
386 goto err_conn;
387 if (rc == -2)
388 return -2;
389
390 /* get total size of mailbox */
391 mutt_str_copy(buf, "STAT\r\n", sizeof(buf));
392 rc = pop_query(adata, buf, sizeof(buf));
393 if (rc == -1)
394 goto err_conn;
395 if (rc == -2)
396 {
397 mutt_error("%s", adata->err_msg);
398 return rc;
399 }
400
401 unsigned int n = 0, size = 0;
402 sscanf(buf, "+OK %u %u", &n, &size);
403 adata->size = size;
404 return 0;
405
406err_conn:
407 adata->status = POP_DISCONNECTED;
408 mutt_error(_("Server closed connection"));
409 return -1;
410}
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
Definition: helpers.c:218
int mutt_ssl_starttls(struct Connection *conn)
Negotiate TLS over an already opened connection.
Definition: gnutls.c:1143
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:629
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:74
int pop_authenticate(struct PopAccountData *adata)
Authenticate with a POP server.
Definition: auth.c:424
static int pop_capabilities(struct PopAccountData *adata, int mode)
Get capabilities from a POP server.
Definition: lib.c:194
#define pop_query(adata, buf, buflen)
Definition: private.h:109
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(enum QuadOption opt, const char *prompt)
Ask the user a quad-question.
Definition: question.c:386
void mutt_socket_empty(struct Connection *conn)
Clear out any queued data.
Definition: socket.c:313
unsigned int ssf
Security strength factor, in bits (see notes)
Definition: connection.h:51
size_t size
Definition: adata.h:50
bool cmd_stls
optional command STLS
Definition: adata.h:43
unsigned int use_stls
Definition: adata.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pop_query_d()

int pop_query_d ( 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 457 of file lib.c.

458{
459 if (adata->status != POP_CONNECTED)
460 return -1;
461
462 /* print msg instead of real command */
463 if (msg)
464 {
465 mutt_debug(MUTT_SOCK_LOG_CMD, "> %s", msg);
466 }
467
469
470 char *c = strpbrk(buf, " \r\n");
471 if (c)
472 *c = '\0';
473 snprintf(adata->err_msg, sizeof(adata->err_msg), "%s: ", buf);
474
475 if (mutt_socket_readln_d(buf, buflen, adata->conn, MUTT_SOCK_LOG_FULL) < 0)
476 {
477 adata->status = POP_DISCONNECTED;
478 return -1;
479 }
480 if (mutt_str_startswith(buf, "+OK"))
481 return 0;
482
483 pop_error(adata, buf);
484 return -2;
485}
int mutt_socket_readln_d(char *buf, size_t buflen, struct Connection *conn, int dbg)
Read a line from a socket.
Definition: socket.c:246
#define MUTT_SOCK_LOG_FULL
Definition: socket.h:55
#define MUTT_SOCK_LOG_CMD
Definition: socket.h:53
#define mutt_socket_send_d(conn, buf, dbg)
Definition: socket.h:59
+ 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 502 of file lib.c.

504{
505 char buf[1024] = { 0 };
506 long pos = 0;
507 size_t lenbuf = 0;
508
509 mutt_str_copy(buf, query, sizeof(buf));
510 int rc = pop_query(adata, buf, sizeof(buf));
511 if (rc < 0)
512 return rc;
513
514 char *inbuf = mutt_mem_malloc(sizeof(buf));
515
516 while (true)
517 {
518 const int chunk = mutt_socket_readln_d(buf, sizeof(buf), adata->conn, MUTT_SOCK_LOG_FULL);
519 if (chunk < 0)
520 {
521 adata->status = POP_DISCONNECTED;
522 rc = -1;
523 break;
524 }
525
526 char *p = buf;
527 if (!lenbuf && (buf[0] == '.'))
528 {
529 if (buf[1] != '.')
530 break;
531 p++;
532 }
533
534 mutt_str_copy(inbuf + lenbuf, p, sizeof(buf));
535 pos += chunk;
536
537 /* cast is safe since we break out of the loop when chunk<=0 */
538 if ((size_t) chunk >= sizeof(buf))
539 {
540 lenbuf += strlen(p);
541 }
542 else
543 {
544 if (progress)
545 progress_update(progress, pos, -1);
546 if ((rc == 0) && (callback(inbuf, data) < 0))
547 rc = -3;
548 lenbuf = 0;
549 }
550
551 mutt_mem_realloc(&inbuf, lenbuf + sizeof(buf));
552 }
553
554 FREE(&inbuf);
555 return rc;
556}
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
bool progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
Definition: progress.c:73
+ 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 599 of file lib.c.

600{
602
603 if (adata->status == POP_CONNECTED)
604 return 0;
605
606 while (true)
607 {
609
610 int rc = pop_open_connection(adata);
611 if (rc == 0)
612 {
613 struct Progress *progress = progress_new(_("Verifying message indexes..."),
615
616 for (int i = 0; i < m->msg_count; i++)
617 {
618 struct PopEmailData *edata = pop_edata_get(m->emails[i]);
619 edata->refno = -1;
620 }
621
622 rc = pop_fetch_data(adata, "UIDL\r\n", progress, check_uidl, m);
623 progress_free(&progress);
624 if (rc == -2)
625 {
626 mutt_error("%s", adata->err_msg);
627 }
628 }
629
630 if (rc == 0)
631 return 0;
632
633 pop_logout(m);
634
635 if (rc < -1)
636 return -1;
637
638 const enum QuadOption c_pop_reconnect = cs_subset_quad(NeoMutt->sub, "pop_reconnect");
639 if (query_quadoption(c_pop_reconnect, _("Connection lost. Reconnect to POP server?")) != MUTT_YES)
640 {
641 return -1;
642 }
643 }
644}
static int check_uidl(const char *line, void *data)
Find message with this UIDL and set refno - Implements pop_fetch_t -.
Definition: lib.c:565
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:64
struct PopEmailData * pop_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:65
int pop_open_connection(struct PopAccountData *adata)
Open connection and authenticate.
Definition: lib.c:308
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:502
void pop_logout(struct Mailbox *m)
Logout from a POP server.
Definition: lib.c:416
@ MUTT_PROGRESS_NET
Progress tracks bytes, according to $net_inc
Definition: lib.h:51
void progress_free(struct Progress **ptr)
Free a Progress Bar.
Definition: progress.c:86
struct Progress * progress_new(const char *msg, enum ProgressType type, size_t size)
Create a new Progress Bar.
Definition: progress.c:118
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition: socket.c:97
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
void * edata
Driver-specific data.
Definition: email.h:72
int msg_count
Total number of messages.
Definition: mailbox.h:88
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
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 416 of file lib.c.

417{
419
420 if (adata->status == POP_CONNECTED)
421 {
422 int rc = 0;
423 char buf[1024] = { 0 };
424 mutt_message(_("Closing connection to POP server..."));
425
426 if (m->readonly)
427 {
428 mutt_str_copy(buf, "RSET\r\n", sizeof(buf));
429 rc = pop_query(adata, buf, sizeof(buf));
430 }
431
432 if (rc != -1)
433 {
434 mutt_str_copy(buf, "QUIT\r\n", sizeof(buf));
435 rc = pop_query(adata, buf, sizeof(buf));
436 }
437
438 if (rc < 0)
439 mutt_debug(LL_DEBUG1, "Error closing POP connection\n");
440
442 }
443
444 adata->status = POP_DISCONNECTED;
445}
#define mutt_message(...)
Definition: logging.h:86
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
bool readonly
Don't allow changes to the mailbox.
Definition: mailbox.h:116
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pop_get_field()

const char * pop_get_field ( enum ConnAccountField  field,
void *  gf_data 
)

Get connection login credentials - Implements ConnAccount::get_field()

Definition at line 56 of file lib.c.

57{
58 switch (field)
59 {
60 case MUTT_CA_LOGIN:
61 case MUTT_CA_USER:
62 return cs_subset_string(NeoMutt->sub, "pop_user");
63 case MUTT_CA_PASS:
64 return cs_subset_string(NeoMutt->sub, "pop_pass");
66 return cs_subset_string(NeoMutt->sub, "pop_oauth_refresh_command");
67 case MUTT_CA_HOST:
68 default:
69 return NULL;
70 }
71}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
@ MUTT_CA_OAUTH_CMD
OAuth refresh command.
Definition: connaccount.h:38
@ MUTT_CA_USER
User name.
Definition: connaccount.h:36
@ MUTT_CA_LOGIN
Login name.
Definition: connaccount.h:35
@ MUTT_CA_HOST
Server name.
Definition: connaccount.h:34
@ MUTT_CA_PASS
Password.
Definition: connaccount.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function: