NeoMutt  2020-04-24
Teaching an old dog new tricks
DOXYGEN
pop.c File Reference

POP network mailbox. More...

#include "config.h"
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "pop_private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "conn/lib.h"
#include "lib.h"
#include "context.h"
#include "globals.h"
#include "hook.h"
#include "init.h"
#include "mutt_account.h"
#include "mutt_header.h"
#include "mutt_logging.h"
#include "mutt_socket.h"
#include "muttlib.h"
#include "mx.h"
#include "progress.h"
#include "bcache/lib.h"
#include "ncrypt/lib.h"
#include <libintl.h>
#include "hcache/lib.h"
+ Include dependency graph for pop.c:

Go to the source code of this file.

Macros

#define HC_FNAME   "neomutt" /* filename for hcache as POP lacks paths */
 
#define HC_FEXT   "hcache" /* extension for hcache as POP lacks paths */
 

Functions

static const char * cache_id (const char *id)
 Make a message-cache-compatible id. More...
 
static void pop_adata_free (void **ptr)
 Free data attached to the Mailbox. More...
 
static struct PopAccountDatapop_adata_new (void)
 Create a new PopAccountData object. More...
 
static void pop_edata_free (void **ptr)
 Free data attached to an Email. More...
 
static struct PopEmailDatapop_edata_new (const char *uid)
 Create a new PopEmailData for an email. More...
 
static int fetch_message (const char *line, void *data)
 write line to file - Implements pop_fetch_t More...
 
static int pop_read_header (struct PopAccountData *adata, struct Email *e)
 Read header. More...
 
static int fetch_uidl (const char *line, void *data)
 parse UIDL - Implements pop_fetch_t More...
 
static int msg_cache_check (const char *id, struct BodyCache *bcache, void *data)
 Check the Body Cache for an ID - Implements bcache_list_t. More...
 
static void pop_hcache_namer (const char *path, struct Buffer *dest)
 Create a header cache filename for a POP mailbox - Implements hcache_namer_t. More...
 
static header_cache_tpop_hcache_open (struct PopAccountData *adata, const char *path)
 Open the header cache. More...
 
static int pop_fetch_headers (struct Mailbox *m)
 Read headers. More...
 
static void pop_clear_cache (struct PopAccountData *adata)
 delete all cached messages More...
 
void pop_fetch_mail (void)
 Fetch messages and save them in $spoolfile. More...
 
static struct Accountpop_ac_find (struct Account *a, const char *path)
 Find an Account that matches a Mailbox path - Implements MxOps::ac_find() More...
 
static int pop_ac_add (struct Account *a, struct Mailbox *m)
 Add a Mailbox to an Account - Implements MxOps::ac_add() More...
 
static int pop_mbox_open (struct Mailbox *m)
 Open a Mailbox - Implements MxOps::mbox_open() More...
 
static int pop_mbox_check (struct Mailbox *m, int *index_hint)
 Check for new mail - Implements MxOps::mbox_check() More...
 
static int pop_mbox_sync (struct Mailbox *m, int *index_hint)
 Save changes to the Mailbox - Implements MxOps::mbox_sync() More...
 
static int pop_mbox_close (struct Mailbox *m)
 Close a Mailbox - Implements MxOps::mbox_close() More...
 
static int pop_msg_open (struct Mailbox *m, struct Message *msg, int msgno)
 Open an email message in a Mailbox - Implements MxOps::msg_open() More...
 
static int pop_msg_close (struct Mailbox *m, struct Message *msg)
 Close an email - Implements MxOps::msg_close() More...
 
static int pop_msg_save_hcache (struct Mailbox *m, struct Email *e)
 Save message to the header cache - Implements MxOps::msg_save_hcache() More...
 
enum MailboxType pop_path_probe (const char *path, const struct stat *st)
 Is this a POP Mailbox? - Implements MxOps::path_probe() More...
 
static int pop_path_canon (char *buf, size_t buflen)
 Canonicalise a Mailbox path - Implements MxOps::path_canon() More...
 
static int pop_path_pretty (char *buf, size_t buflen, const char *folder)
 Abbreviate a Mailbox path - Implements MxOps::path_pretty() More...
 
static int pop_path_parent (char *buf, size_t buflen)
 Find the parent of a Mailbox path - Implements MxOps::path_parent() More...
 

Variables

short C_PopCheckinterval
 Config: (pop) Interval between checks for new mail. More...
 
unsigned char C_PopDelete
 Config: (pop) After downloading POP messages, delete them on the server. More...
 
char * C_PopHost
 Config: (pop) Url of the POP server. More...
 
bool C_PopLast
 Config: (pop) Use the 'LAST' command to fetch new mail. More...
 
struct MxOps MxPopOps
 POP Mailbox - Implements MxOps. More...
 

Detailed Description

POP network mailbox.

Authors
  • Vsevolod Volkov
  • Rocco Rutte
  • 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 pop.c.

Macro Definition Documentation

◆ HC_FNAME

#define HC_FNAME   "neomutt" /* filename for hcache as POP lacks paths */

Definition at line 75 of file pop.c.

◆ HC_FEXT

#define HC_FEXT   "hcache" /* extension for hcache as POP lacks paths */

Definition at line 76 of file pop.c.

Function Documentation

◆ cache_id()

static const char* cache_id ( const char *  id)
static

Make a message-cache-compatible id.

Parameters
idPOP message id
Return values
ptrSanitised string

The POP message id may contain '/' and other awkward characters.

Note
This function returns a pointer to a static buffer.

Definition at line 87 of file pop.c.

88 {
89  static char clean[128];
90  mutt_str_strfcpy(clean, id, sizeof(clean));
91  mutt_file_sanitize_filename(clean, true);
92  return clean;
93 }
void mutt_file_sanitize_filename(char *path, bool slash)
Replace unsafe characters in a filename.
Definition: file.c:618
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:776
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pop_adata_free()

static void pop_adata_free ( void **  ptr)
static

Free data attached to the Mailbox.

Parameters
[out]ptrPOP data

The PopAccountData struct stores global POP data, such as the connection to the database. This function will close the database, free the resources and the struct itself.

Definition at line 103 of file pop.c.

104 {
105  if (!ptr || !*ptr)
106  return;
107 
108  struct PopAccountData *adata = *ptr;
109  FREE(&adata->auth_list.data);
110  FREE(ptr);
111 }
struct Buffer auth_list
list of auth mechanisms
Definition: pop_private.h:95
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
char * data
Pointer to data.
Definition: buffer.h:35
#define FREE(x)
Definition: memory.h:40
POP-specific Account data -.
Definition: pop_private.h:78
+ Here is the caller graph for this function:

◆ pop_adata_new()

static struct PopAccountData* pop_adata_new ( void  )
static

Create a new PopAccountData object.

Return values
ptrNew PopAccountData struct

Definition at line 117 of file pop.c.

118 {
119  return mutt_mem_calloc(1, sizeof(struct PopAccountData));
120 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
POP-specific Account data -.
Definition: pop_private.h:78
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pop_edata_free()

static void pop_edata_free ( void **  ptr)
static

Free data attached to an Email.

Parameters
[out]ptrEmail data

Each email has an attached PopEmailData, which contains things like the tags (labels).

Definition at line 129 of file pop.c.

130 {
131  if (!ptr || !*ptr)
132  return;
133 
134  struct PopEmailData *edata = *ptr;
135  FREE(&edata->uid);
136  FREE(ptr);
137 }
const char * uid
Definition: pop_private.h:107
POP-specific Email data -.
Definition: pop_private.h:105
void * edata
Driver-specific data.
Definition: email.h:106
#define FREE(x)
Definition: memory.h:40
+ Here is the caller graph for this function:

◆ pop_edata_new()

static struct PopEmailData* pop_edata_new ( const char *  uid)
static

Create a new PopEmailData for an email.

Parameters
uidEmail UID
Return values
ptrNew PopEmailData struct

Definition at line 144 of file pop.c.

145 {
146  struct PopEmailData *edata = mutt_mem_calloc(1, sizeof(struct PopEmailData));
147  edata->uid = mutt_str_strdup(uid);
148  return edata;
149 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
const char * uid
Definition: pop_private.h:107
POP-specific Email data -.
Definition: pop_private.h:105
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:380
void * edata
Driver-specific data.
Definition: email.h:106
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fetch_message()

static int fetch_message ( const char *  line,
void *  data 
)
static

write line to file - Implements pop_fetch_t

Parameters
lineString to write
dataFILE pointer to write to
Return values
0Success
-1Failure

Definition at line 158 of file pop.c.

159 {
160  FILE *fp = data;
161 
162  fputs(line, fp);
163  if (fputc('\n', fp) == EOF)
164  return -1;
165 
166  return 0;
167 }
int const char int line
Definition: acutest.h:617
+ Here is the caller graph for this function:

◆ pop_read_header()

static int pop_read_header ( struct PopAccountData adata,
struct Email e 
)
static

Read header.

Parameters
adataPOP Account data
eEmail
Return values
0Success
-1Connection lost
-2Invalid command or execution error
-3Error writing to tempfile

Definition at line 178 of file pop.c.

179 {
180  FILE *fp = mutt_file_mkstemp();
181  if (!fp)
182  {
183  mutt_perror(_("Can't create temporary file"));
184  return -3;
185  }
186 
187  int index = 0;
188  size_t length = 0;
189  char buf[1024];
190 
191  struct PopEmailData *edata = pop_edata_get(e);
192 
193  snprintf(buf, sizeof(buf), "LIST %d\r\n", edata->refno);
194  int rc = pop_query(adata, buf, sizeof(buf));
195  if (rc == 0)
196  {
197  sscanf(buf, "+OK %d %zu", &index, &length);
198 
199  snprintf(buf, sizeof(buf), "TOP %d 0\r\n", edata->refno);
200  rc = pop_fetch_data(adata, buf, NULL, fetch_message, fp);
201 
202  if (adata->cmd_top == 2)
203  {
204  if (rc == 0)
205  {
206  adata->cmd_top = 1;
207 
208  mutt_debug(LL_DEBUG1, "set TOP capability\n");
209  }
210 
211  if (rc == -2)
212  {
213  adata->cmd_top = 0;
214 
215  mutt_debug(LL_DEBUG1, "unset TOP capability\n");
216  snprintf(adata->err_msg, sizeof(adata->err_msg), "%s",
217  _("Command TOP is not supported by server"));
218  }
219  }
220  }
221 
222  switch (rc)
223  {
224  case 0:
225  {
226  rewind(fp);
227  e->env = mutt_rfc822_read_header(fp, e, false, false);
228  e->content->length = length - e->content->offset + 1;
229  rewind(fp);
230  while (!feof(fp))
231  {
232  e->content->length--;
233  fgets(buf, sizeof(buf), fp);
234  }
235  break;
236  }
237  case -2:
238  {
239  mutt_error("%s", adata->err_msg);
240  break;
241  }
242  case -3:
243  {
244  mutt_error(_("Can't write header to temporary file"));
245  break;
246  }
247  }
248 
249  mutt_file_fclose(&fp);
250  return rc;
251 }
char err_msg[POP_CMD_RESPONSE]
Definition: pop_private.h:98
#define mutt_perror(...)
Definition: logging.h:85
#define pop_query(adata, buf, buflen)
Definition: pop_private.h:142
struct Body * content
List of MIME parts.
Definition: email.h:90
LOFF_T offset
offset where the actual data begins
Definition: body.h:44
#define _(a)
Definition: message.h:28
int refno
Message number on server.
Definition: pop_private.h:108
struct PopEmailData * pop_edata_get(struct Email *e)
Get the private data for this Email.
Definition: pop_lib.c:278
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
struct Envelope * env
Envelope information.
Definition: email.h:89
LOFF_T length
length (in bytes) of attachment
Definition: body.h:45
#define mutt_file_mkstemp()
Definition: file.h:105
unsigned int cmd_top
optional command TOP
Definition: pop_private.h:88
POP-specific Email data -.
Definition: pop_private.h:105
Log at debug level 1.
Definition: logging.h:40
void * edata
Driver-specific data.
Definition: email.h:106
#define mutt_error(...)
Definition: logging.h:84
int index
The absolute (unsorted) message number.
Definition: email.h:85
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct Envelope * mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed)
parses an RFC822 header
Definition: parse.c:1137
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: pop_lib.c:518
static int fetch_message(const char *line, void *data)
write line to file - Implements pop_fetch_t
Definition: pop.c:158
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fetch_uidl()

static int fetch_uidl ( const char *  line,
void *  data 
)
static

parse UIDL - Implements pop_fetch_t

Parameters
lineString to parse
dataMailbox
Return values
0Success
-1Failure

Definition at line 260 of file pop.c.

261 {
262  struct Mailbox *m = data;
263  struct PopAccountData *adata = pop_adata_get(m);
264  char *endp = NULL;
265 
266  errno = 0;
267  int index = strtol(line, &endp, 10);
268  if (errno)
269  return -1;
270  while (*endp == ' ')
271  endp++;
272  line = endp;
273 
274  /* uid must be at least be 1 byte */
275  if (strlen(line) == 0)
276  return -1;
277 
278  int i;
279  for (i = 0; i < m->msg_count; i++)
280  {
281  struct PopEmailData *edata = pop_edata_get(m->emails[i]);
282  if (mutt_str_strcmp(line, edata->uid) == 0)
283  break;
284  }
285 
286  if (i == m->msg_count)
287  {
288  mutt_debug(LL_DEBUG1, "new header %d %s\n", index, line);
289 
290  if (i >= m->email_max)
291  mx_alloc_memory(m);
292 
293  m->msg_count++;
294  m->emails[i] = email_new();
295 
296  m->emails[i]->edata = pop_edata_new(line);
298  }
299  else if (m->emails[i]->index != index - 1)
300  adata->clear_cache = true;
301 
302  m->emails[i]->index = index - 1;
303 
304  struct PopEmailData *edata = pop_edata_get(m->emails[i]);
305  edata->refno = index;
306 
307  return 0;
308 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
int msg_count
Total number of messages.
Definition: mailbox.h:91
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: pop_lib.c:666
void mx_alloc_memory(struct Mailbox *m)
Create storage for the emails.
Definition: mx.c:1197
static struct PopEmailData * pop_edata_new(const char *uid)
Create a new PopEmailData for an email.
Definition: pop.c:144
int refno
Message number on server.
Definition: pop_private.h:108
struct PopEmailData * pop_edata_get(struct Email *e)
Get the private data for this Email.
Definition: pop_lib.c:278
const char * uid
Definition: pop_private.h:107
int email_max
Number of pointers in emails.
Definition: mailbox.h:100
A mailbox.
Definition: mailbox.h:81
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
POP-specific Email data -.
Definition: pop_private.h:105
static void pop_edata_free(void **ptr)
Free data attached to an Email.
Definition: pop.c:129
Log at debug level 1.
Definition: logging.h:40
void * edata
Driver-specific data.
Definition: email.h:106
int index
The absolute (unsorted) message number.
Definition: email.h:85
struct Email * email_new(void)
Create a new Email.
Definition: email.c:68
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
POP-specific Account data -.
Definition: pop_private.h:78
int const char int line
Definition: acutest.h:617
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:641
void(* free_edata)(void **ptr)
Driver-specific data free function.
Definition: email.h:107
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ msg_cache_check()

static int msg_cache_check ( const char *  id,
struct BodyCache bcache,
void *  data 
)
static

Check the Body Cache for an ID - Implements bcache_list_t.

Definition at line 313 of file pop.c.

314 {
315  struct Mailbox *m = data;
316  if (!m)
317  return -1;
318 
319  struct PopAccountData *adata = pop_adata_get(m);
320  if (!adata)
321  return -1;
322 
323 #ifdef USE_HCACHE
324  /* keep hcache file if hcache == bcache */
325  if (strcmp(HC_FNAME "." HC_FEXT, id) == 0)
326  return 0;
327 #endif
328 
329  for (int i = 0; i < m->msg_count; i++)
330  {
331  struct PopEmailData *edata = pop_edata_get(m->emails[i]);
332  /* if the id we get is known for a header: done (i.e. keep in cache) */
333  if (edata->uid && (mutt_str_strcmp(edata->uid, id) == 0))
334  return 0;
335  }
336 
337  /* message not found in context -> remove it from cache
338  * return the result of bcache, so we stop upon its first error */
339  return mutt_bcache_del(bcache, cache_id(id));
340 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
int msg_count
Total number of messages.
Definition: mailbox.h:91
#define HC_FNAME
Definition: pop.c:75
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: pop_lib.c:666
static const char * cache_id(const char *id)
Make a message-cache-compatible id.
Definition: pop.c:87
struct PopEmailData * pop_edata_get(struct Email *e)
Get the private data for this Email.
Definition: pop_lib.c:278
const char * uid
Definition: pop_private.h:107
A mailbox.
Definition: mailbox.h:81
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
int mutt_bcache_del(struct BodyCache *bcache, const char *id)
Delete a file from the Body Cache.
Definition: bcache.c:252
POP-specific Email data -.
Definition: pop_private.h:105
#define HC_FEXT
Definition: pop.c:76
void * edata
Driver-specific data.
Definition: email.h:106
POP-specific Account data -.
Definition: pop_private.h:78
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:641
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pop_hcache_namer()

static void pop_hcache_namer ( const char *  path,
struct Buffer dest 
)
static

Create a header cache filename for a POP mailbox - Implements hcache_namer_t.

Definition at line 346 of file pop.c.

347 {
348  mutt_buffer_printf(dest, "%s." HC_FEXT, path);
349 }
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
#define HC_FEXT
Definition: pop.c:76
char * path
Path of Email (for local Mailboxes)
Definition: email.h:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pop_hcache_open()

static header_cache_t* pop_hcache_open ( struct PopAccountData adata,
const char *  path 
)
static

Open the header cache.

Parameters
adataPOP Account data
pathPath to the mailbox
Return values
ptrHeader cache

Definition at line 357 of file pop.c.

358 {
359  if (!adata || !adata->conn)
360  return mutt_hcache_open(C_HeaderCache, path, NULL);
361 
362  struct Url url = { 0 };
363  char p[1024];
364 
365  mutt_account_tourl(&adata->conn->account, &url);
366  url.path = HC_FNAME;
367  url_tostring(&url, p, sizeof(p), U_PATH);
369 }
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:36
#define HC_FNAME
Definition: pop.c:75
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:66
struct Connection * conn
Definition: pop_private.h:80
WHERE char * C_HeaderCache
Config: (hcache) Directory/file for the header cache database.
Definition: globals.h:123
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:79
header_cache_t * mutt_hcache_open(const char *path, const char *folder, hcache_namer_t namer)
Multiplexor for StoreOps::open.
Definition: hcache.c:326
char * path
Path.
Definition: url.h:73
static void pop_hcache_namer(const char *path, struct Buffer *dest)
Create a header cache filename for a POP mailbox - Implements hcache_namer_t.
Definition: pop.c:346
char * path
Path of Email (for local Mailboxes)
Definition: email.h:91
int url_tostring(struct Url *url, char *dest, size_t len, int flags)
Output the URL string for a given Url object.
Definition: url.c:416
#define U_PATH
Definition: url.h:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pop_fetch_headers()

static int pop_fetch_headers ( struct Mailbox m)
static

Read headers.

Parameters
mMailbox
Return values
0Success
-1Connection lost
-2Invalid command or execution error
-3Error writing to tempfile

Definition at line 380 of file pop.c.

381 {
382  if (!m)
383  return -1;
384 
385  struct PopAccountData *adata = pop_adata_get(m);
386  struct Progress progress;
387 
388 #ifdef USE_HCACHE
390 #endif
391 
392  adata->check_time = mutt_date_epoch();
393  adata->clear_cache = false;
394 
395  for (int i = 0; i < m->msg_count; i++)
396  {
397  struct PopEmailData *edata = pop_edata_get(m->emails[i]);
398  edata->refno = -1;
399  }
400 
401  const int old_count = m->msg_count;
402  int rc = pop_fetch_data(adata, "UIDL\r\n", NULL, fetch_uidl, m);
403  const int new_count = m->msg_count;
404  m->msg_count = old_count;
405 
406  if (adata->cmd_uidl == 2)
407  {
408  if (rc == 0)
409  {
410  adata->cmd_uidl = 1;
411 
412  mutt_debug(LL_DEBUG1, "set UIDL capability\n");
413  }
414 
415  if ((rc == -2) && (adata->cmd_uidl == 2))
416  {
417  adata->cmd_uidl = 0;
418 
419  mutt_debug(LL_DEBUG1, "unset UIDL capability\n");
420  snprintf(adata->err_msg, sizeof(adata->err_msg), "%s",
421  _("Command UIDL is not supported by server"));
422  }
423  }
424 
425  if (!m->quiet)
426  {
427  mutt_progress_init(&progress, _("Fetching message headers..."),
428  MUTT_PROGRESS_READ, new_count - old_count);
429  }
430 
431  if (rc == 0)
432  {
433  int i, deleted;
434  for (i = 0, deleted = 0; i < old_count; i++)
435  {
436  struct PopEmailData *edata = pop_edata_get(m->emails[i]);
437  if (edata->refno == -1)
438  {
439  m->emails[i]->deleted = true;
440  deleted++;
441  }
442  }
443  if (deleted > 0)
444  {
445  mutt_error(
446  ngettext("%d message has been lost. Try reopening the mailbox.",
447  "%d messages have been lost. Try reopening the mailbox.", deleted),
448  deleted);
449  }
450 
451  bool hcached = false;
452  for (i = old_count; i < new_count; i++)
453  {
454  if (!m->quiet)
455  mutt_progress_update(&progress, i + 1 - old_count, -1);
456  struct PopEmailData *edata = pop_edata_get(m->emails[i]);
457 #ifdef USE_HCACHE
458  struct HCacheEntry hce = mutt_hcache_fetch(hc, edata->uid, strlen(edata->uid), 0);
459  if (hce.email)
460  {
461  /* Detach the private data */
462  m->emails[i]->edata = NULL;
463 
464  int index = m->emails[i]->index;
465  /* - POP dynamically numbers headers and relies on e->refno
466  * to map messages; so restore header and overwrite restored
467  * refno with current refno, same for index
468  * - e->data needs to a separate pointer as it's driver-specific
469  * data freed separately elsewhere
470  * (the old e->data should point inside a malloc'd block from
471  * hcache so there shouldn't be a memleak here) */
472  email_free(&m->emails[i]);
473  m->emails[i] = hce.email;
474  m->emails[i]->index = index;
475 
476  /* Reattach the private data */
477  m->emails[i]->edata = edata;
479  rc = 0;
480  hcached = true;
481  }
482  else
483 #endif
484  if ((rc = pop_read_header(adata, m->emails[i])) < 0)
485  break;
486 #ifdef USE_HCACHE
487  else
488  {
489  mutt_hcache_store(hc, edata->uid, strlen(edata->uid), m->emails[i], 0);
490  }
491 #endif
492 
493  /* faked support for flags works like this:
494  * - if 'hcached' is true, we have the message in our hcache:
495  * - if we also have a body: read
496  * - if we don't have a body: old
497  * (if $mark_old is set which is maybe wrong as
498  * $mark_old should be considered for syncing the
499  * folder and not when opening it XXX)
500  * - if 'hcached' is false, we don't have the message in our hcache:
501  * - if we also have a body: read
502  * - if we don't have a body: new */
503  const bool bcached =
504  (mutt_bcache_exists(adata->bcache, cache_id(edata->uid)) == 0);
505  m->emails[i]->old = false;
506  m->emails[i]->read = false;
507  if (hcached)
508  {
509  if (bcached)
510  m->emails[i]->read = true;
511  else if (C_MarkOld)
512  m->emails[i]->old = true;
513  }
514  else
515  {
516  if (bcached)
517  m->emails[i]->read = true;
518  }
519 
520  m->msg_count++;
521  }
522  }
523 
524 #ifdef USE_HCACHE
525  mutt_hcache_close(hc);
526 #endif
527 
528  if (rc < 0)
529  {
530  for (int i = m->msg_count; i < new_count; i++)
531  email_free(&m->emails[i]);
532  return rc;
533  }
534 
535  /* after putting the result into our structures,
536  * clean up cache, i.e. wipe messages deleted outside
537  * the availability of our cache */
540 
542  return new_count - old_count;
543 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:417
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:192
WHERE bool C_MessageCacheClean
Config: (imap/pop) Clean out obsolete entries from the message cache.
Definition: globals.h:240
int msg_count
Total number of messages.
Definition: mailbox.h:91
char err_msg[POP_CMD_RESPONSE]
Definition: pop_private.h:98
Wrapper for Email retrieved from the header cache.
Definition: lib.h:96
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: pop_lib.c:666
struct BodyCache * bcache
body cache
Definition: pop_private.h:97
struct HCacheEntry mutt_hcache_fetch(header_cache_t *hc, const char *key, size_t keylen, uint32_t uidvalidity)
Multiplexor for StoreOps::fetch.
Definition: hcache.c:441
#define _(a)
Definition: message.h:28
static const char * cache_id(const char *id)
Make a message-cache-compatible id.
Definition: pop.c:87
int refno
Message number on server.
Definition: pop_private.h:108
struct PopEmailData * pop_edata_get(struct Email *e)
Get the private data for this Email.
Definition: pop_lib.c:278
A progress bar.
Definition: progress.h:49
static int msg_cache_check(const char *id, struct BodyCache *bcache, void *data)
Check the Body Cache for an ID - Implements bcache_list_t.
Definition: pop.c:313
int mutt_bcache_list(struct BodyCache *bcache, bcache_list_t want_id, void *data)
Find matching entries in the Body Cache.
Definition: bcache.c:317
void mutt_hcache_close(header_cache_t *hc)
Multiplexor for StoreOps::close.
Definition: hcache.c:422
bool read
Email is read.
Definition: email.h:51
void mutt_progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
Definition: progress.c:212
int mutt_hcache_store(header_cache_t *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
Definition: hcache.c:529
bool old
Email is seen, but unread.
Definition: email.h:50
const char * uid
Definition: pop_private.h:107
Progress tracks elements, according to C_ReadInc.
Definition: progress.h:41
int mutt_bcache_exists(struct BodyCache *bcache, const char *id)
Check if a file exists in the Body Cache.
Definition: bcache.c:275
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
time_t check_time
Definition: pop_private.h:93
static int fetch_uidl(const char *line, void *data)
parse UIDL - Implements pop_fetch_t
Definition: pop.c:260
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
unsigned int cmd_uidl
optional command UIDL
Definition: pop_private.h:87
static int pop_read_header(struct PopAccountData *adata, struct Email *e)
Read header.
Definition: pop.c:178
bool quiet
Inhibit status messages?
Definition: mailbox.h:118
void mutt_progress_init(struct Progress *progress, const char *msg, enum ProgressType type, size_t size)
Set up a progress bar.
Definition: progress.c:153
POP-specific Email data -.
Definition: pop_private.h:105
static header_cache_t * pop_hcache_open(struct PopAccountData *adata, const char *path)
Open the header cache.
Definition: pop.c:357
static void pop_edata_free(void **ptr)
Free data attached to an Email.
Definition: pop.c:129
bool C_MarkOld
Config: Mark new emails as old when leaving the mailbox.
Definition: email_globals.c:36
Log at debug level 1.
Definition: logging.h:40
bool deleted
Email is deleted.
Definition: email.h:45
void * edata
Driver-specific data.
Definition: email.h:106
#define mutt_error(...)
Definition: logging.h:84
int index
The absolute (unsorted) message number.
Definition: email.h:85
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct Email * email
Retrieved email.
Definition: lib.h:100
POP-specific Account data -.
Definition: pop_private.h:78
header cache structure
Definition: lib.h:83
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:41
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: pop_lib.c:518
void(* free_edata)(void **ptr)
Driver-specific data free function.
Definition: email.h:107
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pop_clear_cache()

static void pop_clear_cache ( struct PopAccountData adata)
static

delete all cached messages

Parameters
adataPOP Account data

Definition at line 549 of file pop.c.

550 {
551  if (!adata->clear_cache)
552  return;
553 
554  mutt_debug(LL_DEBUG1, "delete cached messages\n");
555 
556  for (int i = 0; i < POP_CACHE_LEN; i++)
557  {
558  if (adata->cache[i].path)
559  {
560  unlink(adata->cache[i].path);
561  FREE(&adata->cache[i].path);
562  }
563  }
564 }
char * path
Definition: pop_private.h:72
struct PopCache cache[POP_CACHE_LEN]
Definition: pop_private.h:99
#define POP_CACHE_LEN
Definition: pop_private.h:40
Log at debug level 1.
Definition: logging.h:40
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
+ Here is the caller graph for this function:

◆ pop_fetch_mail()

void pop_fetch_mail ( void  )

Fetch messages and save them in $spoolfile.

Definition at line 569 of file pop.c.

570 {
571  if (!C_PopHost)
572  {
573  mutt_error(_("POP host is not defined"));
574  return;
575  }
576 
577  char buf[1024];
578  char msgbuf[128];
579  int last = 0, msgs, bytes, rset = 0, ret;
580  struct ConnAccount cac = { { 0 } };
581 
582  char *p = mutt_mem_calloc(strlen(C_PopHost) + 7, sizeof(char));
583  char *url = p;
585  {
586  strcpy(url, "pop://");
587  p = strchr(url, '\0');
588  }
589  strcpy(p, C_PopHost);
590 
591  ret = pop_parse_path(url, &cac);
592  FREE(&url);
593  if (ret)
594  {
595  mutt_error(_("%s is an invalid POP path"), C_PopHost);
596  return;
597  }
598 
599  struct Connection *conn = mutt_conn_find(&cac);
600  if (!conn)
601  return;
602 
603  struct PopAccountData *adata = pop_adata_new();
604  adata->conn = conn;
605 
606  if (pop_open_connection(adata) < 0)
607  {
608  //XXX mutt_socket_free(adata->conn);
609  pop_adata_free((void **) &adata);
610  return;
611  }
612 
613  mutt_message(_("Checking for new messages..."));
614 
615  /* find out how many messages are in the mailbox. */
616  mutt_str_strfcpy(buf, "STAT\r\n", sizeof(buf));
617  ret = pop_query(adata, buf, sizeof(buf));
618  if (ret == -1)
619  goto fail;
620  if (ret == -2)
621  {
622  mutt_error("%s", adata->err_msg);
623  goto finish;
624  }
625 
626  sscanf(buf, "+OK %d %d", &msgs, &bytes);
627 
628  /* only get unread messages */
629  if ((msgs > 0) && C_PopLast)
630  {
631  mutt_str_strfcpy(buf, "LAST\r\n", sizeof(buf));
632  ret = pop_query(adata, buf, sizeof(buf));
633  if (ret == -1)
634  goto fail;
635  if (ret == 0)
636  sscanf(buf, "+OK %d", &last);
637  }
638 
639  if (msgs <= last)
640  {
641  mutt_message(_("No new mail in POP mailbox"));
642  goto finish;
643  }
644 
645  struct Mailbox *m_spool = mx_path_resolve(C_Spoolfile);
646  struct Context *ctx = mx_mbox_open(m_spool, MUTT_OPEN_NO_FLAGS);
647  if (!ctx)
648  {
649  mailbox_free(&m_spool);
650  goto finish;
651  }
652 
653  bool old_append = m_spool->append;
654  m_spool->append = true;
655 
656  enum QuadOption delanswer =
657  query_quadoption(C_PopDelete, _("Delete messages from server?"));
658 
659  snprintf(msgbuf, sizeof(msgbuf),
660  ngettext("Reading new messages (%d byte)...",
661  "Reading new messages (%d bytes)...", bytes),
662  bytes);
663  mutt_message("%s", msgbuf);
664 
665  for (int i = last + 1; i <= msgs; i++)
666  {
667  struct Message *msg = mx_msg_open_new(ctx->mailbox, NULL, MUTT_ADD_FROM);
668  if (msg)
669  {
670  snprintf(buf, sizeof(buf), "RETR %d\r\n", i);
671  ret = pop_fetch_data(adata, buf, NULL, fetch_message, msg->fp);
672  if (ret == -3)
673  rset = 1;
674 
675  if ((ret == 0) && (mx_msg_commit(ctx->mailbox, msg) != 0))
676  {
677  rset = 1;
678  ret = -3;
679  }
680 
681  mx_msg_close(ctx->mailbox, &msg);
682  }
683  else
684  {
685  ret = -3;
686  }
687 
688  if ((ret == 0) && (delanswer == MUTT_YES))
689  {
690  /* delete the message on the server */
691  snprintf(buf, sizeof(buf), "DELE %d\r\n", i);
692  ret = pop_query(adata, buf, sizeof(buf));
693  }
694 
695  if (ret == -1)
696  {
697  m_spool->append = old_append;
698  mx_mbox_close(&ctx);
699  goto fail;
700  }
701  if (ret == -2)
702  {
703  mutt_error("%s", adata->err_msg);
704  break;
705  }
706  if (ret == -3)
707  {
708  mutt_error(_("Error while writing mailbox"));
709  break;
710  }
711 
712  /* L10N: The plural is picked by the second numerical argument, i.e.
713  the %d right before 'messages', i.e. the total number of messages. */
714  mutt_message(ngettext("%s [%d of %d message read]",
715  "%s [%d of %d messages read]", msgs - last),
716  msgbuf, i - last, msgs - last);
717  }
718 
719  m_spool->append = old_append;
720  mx_mbox_close(&ctx);
721 
722  if (rset)
723  {
724  /* make sure no messages get deleted */
725  mutt_str_strfcpy(buf, "RSET\r\n", sizeof(buf));
726  if (pop_query(adata, buf, sizeof(buf)) == -1)
727  goto fail;
728  }
729 
730 finish:
731  /* exit gracefully */
732  mutt_str_strfcpy(buf, "QUIT\r\n", sizeof(buf));
733  if (pop_query(adata, buf, sizeof(buf)) == -1)
734  goto fail;
735  mutt_socket_close(conn);
736  FREE(&conn);
737  pop_adata_free((void **) &adata);
738  return;
739 
740 fail:
741  mutt_error(_("Server closed connection"));
742  mutt_socket_close(conn);
743  pop_adata_free((void **) &adata);
744 }
enum UrlScheme url_check_scheme(const char *str)
Check the protocol of a URL.
Definition: url.c:219
#define MUTT_OPEN_NO_FLAGS
No flags are set.
Definition: mx.h:52
unsigned char C_PopDelete
Config: (pop) After downloading POP messages, delete them on the server.
Definition: pop.c:71
The "current" mailbox.
Definition: context.h:37
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
char err_msg[POP_CMD_RESPONSE]
Definition: pop_private.h:98
int mx_mbox_close(struct Context **ptr)
Save changes and close mailbox.
Definition: mx.c:593
#define pop_query(adata, buf, buflen)
Definition: pop_private.h:142
enum QuadOption query_quadoption(enum QuadOption opt, const char *prompt)
Ask the user a quad-question.
Definition: init.c:1112
#define mutt_message(...)
Definition: logging.h:83
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:40
An open network connection (socket)
Definition: connection.h:34
Url wasn&#39;t recognised.
Definition: url.h:34
#define _(a)
Definition: message.h:28
struct Connection * conn
Definition: pop_private.h:80
struct Context * mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition: mx.c:255
int pop_parse_path(const char *path, struct ConnAccount *cac)
Parse a POP mailbox name.
Definition: pop_lib.c:88
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
Definition: mx.c:1171
struct Mailbox * mailbox
Definition: context.h:51
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
Definition: mailbox.c:60
char * C_PopHost
Config: (pop) Url of the POP server.
Definition: pop.c:72
struct Message * mx_msg_open_new(struct Mailbox *m, struct Email *e, MsgOpenFlags flags)
Open a new message.
Definition: mx.c:1036
struct Connection * mutt_conn_find(const struct ConnAccount *cac)
Find a connection from a list.
Definition: mutt_socket.c:86
bool C_PopLast
Config: (pop) Use the &#39;LAST&#39; command to fetch new mail.
Definition: pop.c:73
A local copy of an email.
Definition: mx.h:83
A mailbox.
Definition: mailbox.h:81
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:776
bool append
Mailbox is opened in append mode.
Definition: mailbox.h:113
static struct PopAccountData * pop_adata_new(void)
Create a new PopAccountData object.
Definition: pop.c:117
Login details for a remote server.
Definition: connaccount.h:51
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition: socket.c:95
WHERE char * C_Spoolfile
Config: Inbox.
Definition: globals.h:145
static void pop_adata_free(void **ptr)
Free data attached to the Mailbox.
Definition: pop.c:103
#define mutt_error(...)
Definition: logging.h:84
int mx_msg_commit(struct Mailbox *m, struct Message *msg)
Commit a message to a folder - Wrapper for MxOps::msg_commit()
Definition: mx.c:1150
FILE * fp
pointer to the message data
Definition: mx.h:85
#define FREE(x)
Definition: memory.h:40
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
Definition: mx.c:1655
POP-specific Account data -.
Definition: pop_private.h:78
#define MUTT_ADD_FROM
add a From_ line
Definition: mx.h:66
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: pop_lib.c:518
int pop_open_connection(struct PopAccountData *adata)
Open connection and authenticate.
Definition: pop_lib.c:327
QuadOption
Possible values for a quad-option.
Definition: quad.h:36
static int fetch_message(const char *line, void *data)
write line to file - Implements pop_fetch_t
Definition: pop.c:158
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pop_ac_find()

static struct Account* pop_ac_find ( struct Account a,
const char *  path 
)
static

Find an Account that matches a Mailbox path - Implements MxOps::ac_find()

Definition at line 749 of file pop.c.

750 {
751  if (!a || (a->type != MUTT_POP) || !path)
752  return NULL;
753 
754  struct Url *url = url_parse(path);
755  if (!url)
756  return NULL;
757 
758  struct PopAccountData *adata = a->adata;
759  struct ConnAccount *cac = &adata->conn->account;
760 
761  if ((mutt_str_strcasecmp(url->host, cac->host) != 0) ||
762  (mutt_str_strcasecmp(url->user, cac->user) != 0))
763  {
764  a = NULL;
765  }
766 
767  url_free(&url);
768  return a;
769 }
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:36
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:66
char user[128]
Username.
Definition: connaccount.h:55
struct Connection * conn
Definition: pop_private.h:80
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition: url.c:121
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
char host[128]
Server to login to.
Definition: connaccount.h:53
&#39;POP3&#39; Mailbox type
Definition: mailbox.h:55
char * user
Username.
Definition: url.h:69
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
char * host
Host.
Definition: url.h:71
Login details for a remote server.
Definition: connaccount.h:51
char * path
Path.
Definition: url.h:73
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:654
POP-specific Account data -.
Definition: pop_private.h:78
char * path
path to temp file
Definition: mx.h:86
struct Url * url_parse(const char *src)
Fill in Url.
Definition: url.c:232
+ Here is the call graph for this function:

◆ pop_ac_add()

static int pop_ac_add ( struct Account a,
struct Mailbox m 
)
static

Add a Mailbox to an Account - Implements MxOps::ac_add()

Definition at line 774 of file pop.c.

775 {
776  if (!a || !m || (m->type != MUTT_POP))
777  return -1;
778 
779  if (a->adata)
780  return 0;
781 
782  struct ConnAccount cac = { { 0 } };
783  struct PopAccountData *adata = pop_adata_new();
784  a->adata = adata;
786 
787  if (pop_parse_path(mailbox_path(m), &cac))
788  {
789  mutt_error(_("%s is an invalid POP path"), mailbox_path(m));
790  return -1;
791  }
792 
793  adata->conn = mutt_conn_new(&cac);
794  if (!adata->conn)
795  {
796  pop_adata_free((void **) &adata);
797  return -1;
798  }
799 
800  return 0;
801 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:192
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
#define _(a)
Definition: message.h:28
struct Connection * conn
Definition: pop_private.h:80
int pop_parse_path(const char *path, struct ConnAccount *cac)
Parse a POP mailbox name.
Definition: pop_lib.c:88
struct Connection * mutt_conn_new(const struct ConnAccount *cac)
Create a new Connection.
Definition: mutt_socket.c:46
void(* free_adata)(void **ptr)
Callback function to free private data.
Definition: account.h:44
&#39;POP3&#39; Mailbox type
Definition: mailbox.h:55
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
static struct PopAccountData * pop_adata_new(void)
Create a new PopAccountData object.
Definition: pop.c:117
Login details for a remote server.
Definition: connaccount.h:51
static void pop_adata_free(void **ptr)
Free data attached to the Mailbox.
Definition: pop.c:103
#define mutt_error(...)
Definition: logging.h:84
POP-specific Account data -.
Definition: pop_private.h:78
+ Here is the call graph for this function:

◆ pop_mbox_open()

static int pop_mbox_open ( struct Mailbox m)
static

Open a Mailbox - Implements MxOps::mbox_open()

Fetch only headers

Definition at line 808 of file pop.c.

809 {
810  if (!m || !m->account)
811  return -1;
812 
813  char buf[PATH_MAX];
814  struct ConnAccount cac = { { 0 } };
815  struct Url url = { 0 };
816 
817  if (pop_parse_path(mailbox_path(m), &cac))
818  {
819  mutt_error(_("%s is an invalid POP path"), mailbox_path(m));
820  return -1;
821  }
822 
823  mutt_account_tourl(&cac, &url);
824  url.path = NULL;
825  url_tostring(&url, buf, sizeof(buf), 0);
826 
827  mutt_buffer_strcpy(&m->pathbuf, buf);
829 
830  struct PopAccountData *adata = m->account->adata;
831  if (!adata)
832  {
833  adata = pop_adata_new();
834  m->account->adata = adata;
836  }
837 
838  struct Connection *conn = adata->conn;
839  if (!conn)
840  {
841  adata->conn = mutt_conn_new(&cac);
842  conn = adata->conn;
843  if (!conn)
844  return -1;
845  }
846 
847  if (conn->fd < 0)
849 
850  if (pop_open_connection(adata) < 0)
851  return -1;
852 
853  adata->bcache = mutt_bcache_open(&cac, NULL);
854 
855  /* init (hard-coded) ACL rights */
857 #ifdef USE_HCACHE
858  /* flags are managed using header cache, so it only makes sense to
859  * enable them in that case */
860  m->rights |= MUTT_ACL_WRITE;
861 #endif
862 
863  while (true)
864  {
865  if (pop_reconnect(m) < 0)
866  return -1;
867 
868  m->size = adata->size;
869 
870  mutt_message(_("Fetching list of messages..."));
871 
872  const int rc = pop_fetch_headers(m);
873 
874  if (rc >= 0)
875  return 0;
876 
877  if (rc < -1)
878  return -1;
879  }
880 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:192
off_t size
Size of the Mailbox.
Definition: mailbox.h:87
struct BodyCache * mutt_bcache_open(struct ConnAccount *account, const char *mailbox)
Open an Email-Body Cache.
Definition: bcache.c:132
#define mutt_message(...)
Definition: logging.h:83
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition: url.h:66
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
Definition: mailbox.h:84
struct BodyCache * bcache
body cache
Definition: pop_private.h:97
An open network connection (socket)
Definition: connection.h:34
#define _(a)
Definition: message.h:28
struct Connection * conn
Definition: pop_private.h:80
int pop_parse_path(const char *path, struct ConnAccount *cac)
Parse a POP mailbox name.
Definition: pop_lib.c:88
#define MUTT_ACL_DELETE
Delete a message.
Definition: mailbox.h:66
static int pop_fetch_headers(struct Mailbox *m)
Read headers.
Definition: pop.c:380
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:79
#define MUTT_ACL_WRITE
Write to a message (for flagging or linking threads)
Definition: mailbox.h:74
struct Connection * mutt_conn_new(const struct ConnAccount *cac)
Create a new Connection.
Definition: mutt_socket.c:46
void(* free_adata)(void **ptr)
Callback function to free private data.
Definition: account.h:44
void mutt_account_hook(const char *url)
Perform an account hook.
Definition: hook.c:758
#define PATH_MAX
Definition: mutt.h:44
int fd
Socket file descriptor.
Definition: connection.h:40
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
static struct PopAccountData * pop_adata_new(void)
Create a new PopAccountData object.
Definition: pop.c:117
AclFlags rights
ACL bits, see AclFlags.
Definition: mailbox.h:121
Login details for a remote server.
Definition: connaccount.h:51
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:455
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
char * path
Path.
Definition: url.h:73
struct Account * account
Account that owns this Mailbox.
Definition: mailbox.h:131
static void pop_adata_free(void **ptr)
Free data attached to the Mailbox.
Definition: pop.c:103
#define mutt_error(...)
Definition: logging.h:84
int url_tostring(struct Url *url, char *dest, size_t len, int flags)
Output the URL string for a given Url object.
Definition: url.c:416
#define MUTT_ACL_SEEN
Change the &#39;seen&#39; status of a message.
Definition: mailbox.h:73
POP-specific Account data -.
Definition: pop_private.h:78
struct Buffer pathbuf
Definition: mailbox.h:83
int pop_reconnect(struct Mailbox *m)
reconnect and verify indexes if connection was lost
Definition: pop_lib.c:616
int pop_open_connection(struct PopAccountData *adata)
Open connection and authenticate.
Definition: pop_lib.c:327
+ Here is the call graph for this function:

◆ pop_mbox_check()

static int pop_mbox_check ( struct Mailbox m,
int *  index_hint 
)
static

Check for new mail - Implements MxOps::mbox_check()

Definition at line 885 of file pop.c.

886 {
887  if (!m)
888  return -1;
889 
890  struct PopAccountData *adata = pop_adata_get(m);
891 
892  if ((adata->check_time + C_PopCheckinterval) > mutt_date_epoch())
893  return 0;
894 
895  pop_logout(m);
896 
897  mutt_socket_close(adata->conn);
898 
899  if (pop_open_connection(adata) < 0)
900  return -1;
901 
902  m->size = adata->size;
903 
904  mutt_message(_("Checking for new messages..."));
905 
906  int old_msg_count = m->msg_count;
907  int rc = pop_fetch_headers(m);
908  pop_clear_cache(adata);
909  if (m->msg_count > old_msg_count)
911 
912  if (rc < 0)
913  return -1;
914 
915  if (rc > 0)
916  return MUTT_NEW_MAIL;
917 
918  return 0;
919 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:417
int msg_count
Total number of messages.
Definition: mailbox.h:91
off_t size
Size of the Mailbox.
Definition: mailbox.h:87
#define mutt_message(...)
Definition: logging.h:83
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: pop_lib.c:666
#define _(a)
Definition: message.h:28
struct Connection * conn
Definition: pop_private.h:80
Email list was changed.
Definition: mailbox.h:171
static int pop_fetch_headers(struct Mailbox *m)
Read headers.
Definition: pop.c:380
static void pop_clear_cache(struct PopAccountData *adata)
delete all cached messages
Definition: pop.c:549
short C_PopCheckinterval
Config: (pop) Interval between checks for new mail.
Definition: pop.c:67
time_t check_time
Definition: pop_private.h:93
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition: socket.c:95
New mail received in Mailbox.
Definition: mx.h:74
POP-specific Account data -.
Definition: pop_private.h:78
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
Definition: mailbox.c:169
int pop_open_connection(struct PopAccountData *adata)
Open connection and authenticate.
Definition: pop_lib.c:327
void pop_logout(struct Mailbox *m)
logout from a POP server
Definition: pop_lib.c:432
+ Here is the call graph for this function:

◆ pop_mbox_sync()

static int pop_mbox_sync ( struct Mailbox m,
int *  index_hint 
)
static

Save changes to the Mailbox - Implements MxOps::mbox_sync()

Update POP mailbox, delete messages from server

Definition at line 926 of file pop.c.

927 {
928  if (!m)
929  return -1;
930 
931  int i, j, rc = 0;
932  char buf[1024];
933  struct PopAccountData *adata = pop_adata_get(m);
934  struct Progress progress;
935 #ifdef USE_HCACHE
936  header_cache_t *hc = NULL;
937 #endif
938 
939  adata->check_time = 0;
940 
941  int num_deleted = 0;
942  for (i = 0; i < m->msg_count; i++)
943  {
944  if (m->emails[i]->deleted)
945  num_deleted++;
946  }
947 
948  while (true)
949  {
950  if (pop_reconnect(m) < 0)
951  return -1;
952 
953  mutt_progress_init(&progress, _("Marking messages deleted..."),
954  MUTT_PROGRESS_WRITE, num_deleted);
955 
956 #ifdef USE_HCACHE
957  hc = pop_hcache_open(adata, mailbox_path(m));
958 #endif
959 
960  for (i = 0, j = 0, rc = 0; (rc == 0) && (i < m->msg_count); i++)
961  {
962  struct PopEmailData *edata = pop_edata_get(m->emails[i]);
963  if (m->emails[i]->deleted && (edata->refno != -1))
964  {
965  j++;
966  if (!m->quiet)
967  mutt_progress_update(&progress, j, -1);
968  snprintf(buf, sizeof(buf), "DELE %d\r\n", edata->refno);
969  rc = pop_query(adata, buf, sizeof(buf));
970  if (rc == 0)
971  {
972  mutt_bcache_del(adata->bcache, cache_id(edata->uid));
973 #ifdef USE_HCACHE
974  mutt_hcache_delete_header(hc, edata->uid, strlen(edata->uid));
975 #endif
976  }
977  }
978 
979 #ifdef USE_HCACHE
980  if (m->emails[i]->changed)
981  {
982  mutt_hcache_store(hc, edata->uid, strlen(edata->uid), m->emails[i], 0);
983  }
984 #endif
985  }
986 
987 #ifdef USE_HCACHE
988  mutt_hcache_close(hc);
989 #endif
990 
991  if (rc == 0)
992  {
993  mutt_str_strfcpy(buf, "QUIT\r\n", sizeof(buf));
994  rc = pop_query(adata, buf, sizeof(buf));
995  }
996 
997  if (rc == 0)
998  {
999  adata->clear_cache = true;
1000  pop_clear_cache(adata);
1001  adata->status = POP_DISCONNECTED;
1002  return 0;
1003  }
1004 
1005  if (rc == -2)
1006  {
1007  mutt_error("%s", adata->err_msg);
1008  return -1;
1009  }
1010  }
1011 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:192
int msg_count
Total number of messages.
Definition: mailbox.h:91
char err_msg[POP_CMD_RESPONSE]
Definition: pop_private.h:98
#define pop_query(adata, buf, buflen)
Definition: pop_private.h:142
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: pop_lib.c:666
Progress tracks elements, according to C_WriteInc.
Definition: progress.h:42
struct BodyCache * bcache
body cache
Definition: pop_private.h:97
#define _(a)
Definition: message.h:28
bool changed
Email has been edited.
Definition: email.h:48
static const char * cache_id(const char *id)
Make a message-cache-compatible id.
Definition: pop.c:87
int refno
Message number on server.
Definition: pop_private.h:108
struct PopEmailData * pop_edata_get(struct Email *e)
Get the private data for this Email.
Definition: pop_lib.c:278
A progress bar.
Definition: progress.h:49
static void pop_clear_cache(struct PopAccountData *adata)
delete all cached messages
Definition: pop.c:549
void mutt_hcache_close(header_cache_t *hc)
Multiplexor for StoreOps::close.
Definition: hcache.c:422
void mutt_progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
Definition: progress.c:212
int mutt_hcache_store(header_cache_t *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
Definition: hcache.c:529
const char * uid
Definition: pop_private.h:107
time_t check_time
Definition: pop_private.h:93
int mutt_hcache_delete_header(header_cache_t *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_header.
Definition: hcache.c:606
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
size_t mutt_str_strfcpy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:776
bool quiet
Inhibit status messages?
Definition: mailbox.h:118
int mutt_bcache_del(struct BodyCache *bcache, const char *id)
Delete a file from the Body Cache.
Definition: bcache.c:252
void mutt_progress_init(struct Progress *progress, const char *msg, enum ProgressType type, size_t size)
Set up a progress bar.
Definition: progress.c:153
Disconnected from server.
Definition: pop_private.h:52
unsigned int status
Definition: pop_private.h:81
POP-specific Email data -.
Definition: pop_private.h:105
static header_cache_t * pop_hcache_open(struct PopAccountData *adata, const char *path)
Open the header cache.
Definition: pop.c:357
bool deleted
Email is deleted.
Definition: email.h:45
void * edata
Driver-specific data.
Definition: email.h:106
#define mutt_error(...)
Definition: logging.h:84
POP-specific Account data -.
Definition: pop_private.h:78
header cache structure
Definition: lib.h:83
int pop_reconnect(struct Mailbox *m)
reconnect and verify indexes if connection was lost
Definition: pop_lib.c:616
+ Here is the call graph for this function:

◆ pop_mbox_close()

static int pop_mbox_close ( struct Mailbox m)
static

Close a Mailbox - Implements MxOps::mbox_close()

Definition at line 1016 of file pop.c.

1017 {
1018  if (!m)
1019  return -1;
1020 
1021  struct PopAccountData *adata = pop_adata_get(m);
1022  if (!adata)
1023  return 0;
1024 
1025  pop_logout(m);
1026 
1027  if (adata->status != POP_NONE)
1028  {
1029  mutt_socket_close(adata->conn);
1030  // FREE(&adata->conn);
1031  }
1032 
1033  adata->status = POP_NONE;
1034 
1035  adata->clear_cache = true;
1036  pop_clear_cache(adata);
1037 
1038  mutt_bcache_close(&adata->bcache);
1039 
1040  return 0;
1041 }
No connected to server.
Definition: pop_private.h:50
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: pop_lib.c:666
struct BodyCache * bcache
body cache
Definition: pop_private.h:97
struct Connection * conn
Definition: pop_private.h:80
static void pop_clear_cache(struct PopAccountData *adata)
delete all cached messages
Definition: pop.c:549
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
unsigned int status
Definition: pop_private.h:81
int mutt_socket_close(struct Connection *conn)
Close a socket.
Definition: socket.c:95
POP-specific Account data -.
Definition: pop_private.h:78
void mutt_bcache_close(struct BodyCache **bcache)
Close an Email-Body Cache.
Definition: bcache.c:153
void pop_logout(struct Mailbox *m)
logout from a POP server
Definition: pop_lib.c:432
+ Here is the call graph for this function:

◆ pop_msg_open()

static int pop_msg_open ( struct Mailbox m,
struct Message msg,
int  msgno 
)
static

Open an email message in a Mailbox - Implements MxOps::msg_open()

Definition at line 1046 of file pop.c.

1047 {
1048  if (!m)
1049  return -1;
1050 
1051  char buf[1024];
1052  struct Progress progress;
1053  struct PopAccountData *adata = pop_adata_get(m);
1054  struct Email *e = m->emails[msgno];
1055  struct PopEmailData *edata = pop_edata_get(e);
1056  bool bcache = true;
1057  int rc = -1;
1058  struct Buffer *path = NULL;
1059 
1060  /* see if we already have the message in body cache */
1061  msg->fp = mutt_bcache_get(adata->bcache, cache_id(edata->uid));
1062  if (msg->fp)
1063  return 0;
1064 
1065  /* see if we already have the message in our cache in
1066  * case $message_cachedir is unset */
1067  struct PopCache *cache = &adata->cache[e->index % POP_CACHE_LEN];
1068 
1069  if (cache->path)
1070  {
1071  if (cache->index == e->index)
1072  {
1073  /* yes, so just return a pointer to the message */
1074  msg->fp = fopen(cache->path, "r");
1075  if (msg->fp)
1076  return 0;
1077 
1078  mutt_perror(cache->path);
1079  return -1;
1080  }
1081  else
1082  {
1083  /* clear the previous entry */
1084  unlink(cache->path);
1085  FREE(&cache->path);
1086  }
1087  }
1088 
1089  path = mutt_buffer_pool_get();
1090 
1091  while (true)
1092  {
1093  if (pop_reconnect(m) < 0)
1094  goto cleanup;
1095 
1096  /* verify that massage index is correct */
1097  if (edata->refno < 0)
1098  {
1099  mutt_error(
1100  _("The message index is incorrect. Try reopening the mailbox."));
1101  goto cleanup;
1102  }
1103 
1104  mutt_progress_init(&progress, _("Fetching message..."), MUTT_PROGRESS_NET,
1105  e->content->length + e->content->offset - 1);
1106 
1107  /* see if we can put in body cache; use our cache as fallback */
1108  msg->fp = mutt_bcache_put(adata->bcache, cache_id(edata->uid));
1109  if (!msg->fp)
1110  {
1111  /* no */
1112  bcache = false;
1113  mutt_buffer_mktemp(path);
1114  msg->fp = mutt_file_fopen(mutt_b2s(path), "w+");
1115  if (!msg->fp)
1116  {
1117  mutt_perror(mutt_b2s(path));
1118  goto cleanup;
1119  }
1120  }
1121 
1122  snprintf(buf, sizeof(buf), "RETR %d\r\n", edata->refno);
1123 
1124  const int ret = pop_fetch_data(adata, buf, &progress, fetch_message, msg->fp);
1125  if (ret == 0)
1126  break;
1127 
1128  mutt_file_fclose(&msg->fp);
1129 
1130  /* if RETR failed (e.g. connection closed), be sure to remove either
1131  * the file in bcache or from POP's own cache since the next iteration
1132  * of the loop will re-attempt to put() the message */
1133  if (!bcache)
1134  unlink(mutt_b2s(path));
1135 
1136  if (ret == -2)
1137  {
1138  mutt_error("%s", adata->err_msg);
1139  goto cleanup;
1140  }
1141 
1142  if (ret == -3)
1143  {
1144  mutt_error(_("Can't write message to temporary file"));
1145  goto cleanup;
1146  }
1147  }
1148 
1149  /* Update the header information. Previously, we only downloaded a
1150  * portion of the headers, those required for the main display. */
1151  if (bcache)
1152  mutt_bcache_commit(adata->bcache, cache_id(edata->uid));
1153  else
1154  {
1155  cache->index = e->index;
1156  cache->path = mutt_buffer_strdup(path);
1157  }
1158  rewind(msg->fp);
1159 
1160  /* Detach the private data */
1161  e->edata = NULL;
1162 
1163  /* we replace envelope, key in subj_hash has to be updated as well */
1164  if (m->subj_hash && e->env->real_subj)
1166  mutt_label_hash_remove(m, e);
1167  mutt_env_free(&e->env);
1168  e->env = mutt_rfc822_read_header(msg->fp, e, false, false);
1169  if (m->subj_hash && e->env->real_subj)
1171  mutt_label_hash_add(m, e);
1172 
1173  /* Reattach the private data */
1174  e->edata = edata;
1176 
1177  e->lines = 0;
1178  fgets(buf, sizeof(buf), msg->fp);
1179  while (!feof(msg->fp))
1180  {
1181  m->emails[msgno]->lines++;
1182  fgets(buf, sizeof(buf), msg->fp);
1183  }
1184 
1185  e->content->length = ftello(msg->fp) - e->content->offset;
1186 
1187  /* This needs to be done in case this is a multipart message */
1188  if (!WithCrypto)
1189  e->security = crypt_query(e->content);
1190 
1191  mutt_clear_error();
1192  rewind(msg->fp);
1193 
1194  rc = 0;
1195 
1196 cleanup:
1197  mutt_buffer_pool_release(&path);
1198  return rc;
1199 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
Progress tracks bytes, according to C_NetInc.
Definition: progress.h:43
char * path
Definition: pop_private.h:72
#define mutt_buffer_mktemp(buf)
Definition: muttlib.h:81
void mutt_hash_delete(struct Hash *table, const char *strkey, const void *data)
Remove an element from a Hash table.
Definition: hash.c:443
int lines
How many lines in the body of this message?
Definition: email.h:84
char err_msg[POP_CMD_RESPONSE]
Definition: pop_private.h:98
#define WithCrypto
Definition: lib.h:163
The envelope/body of an email.
Definition: email.h:37
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define mutt_perror(...)
Definition: logging.h:85
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: pop_lib.c:666
struct PopCache cache[POP_CACHE_LEN]
Definition: pop_private.h:99
int mutt_bcache_commit(struct BodyCache *bcache, const char *id)
Move a temporary file into the Body Cache.
Definition: bcache.c:235
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Body * content
List of MIME parts.
Definition: email.h:90
struct BodyCache * bcache
body cache
Definition: pop_private.h:97
char * mutt_buffer_strdup(struct Buffer *buf)
Copy a Buffer&#39;s string.
Definition: buffer.c:432
String manipulation buffer.
Definition: buffer.h:33
LOFF_T offset
offset where the actual data begins
Definition: body.h:44
#define _(a)
Definition: message.h:28
char * real_subj
Offset of the real subject.
Definition: envelope.h:67
void mutt_label_hash_add(struct Mailbox *m, struct Email *e)
Add a message&#39;s labels to the Hash Table.
Definition: mutt_header.c:371
static const char * cache_id(const char *id)
Make a message-cache-compatible id.
Definition: pop.c:87
void mutt_label_hash_remove(struct Mailbox *m, struct Email *e)
Remove a message&#39;s labels from the Hash Table.
Definition: mutt_header.c:384
int refno
Message number on server.
Definition: pop_private.h:108
struct PopEmailData * pop_edata_get(struct Email *e)
Get the private data for this Email.
Definition: pop_lib.c:278
A progress bar.
Definition: progress.h:49
FILE * mutt_bcache_get(struct BodyCache *bcache, const char *id)
Open a file in the Body Cache.
Definition: bcache.c:168
const char * uid
Definition: pop_private.h:107
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
struct Envelope * env
Envelope information.
Definition: email.h:89
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Definition: mutt_logging.c:113
FILE * mutt_bcache_put(struct BodyCache *bcache, const char *id)
Create a file in the Body Cache.
Definition: bcache.c:195
#define mutt_b2s(buf)
Definition: buffer.h:41
#define POP_CACHE_LEN
Definition: pop_private.h:40
LOFF_T length
length (in bytes) of attachment
Definition: body.h:45
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:96
void mutt_progress_init(struct Progress *progress, const char *msg, enum ProgressType type, size_t size)
Set up a progress bar.
Definition: progress.c:153
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib...
Definition: email.h:39
POP-specific Email data -.
Definition: pop_private.h:105
static void pop_edata_free(void **ptr)
Free data attached to an Email.
Definition: pop.c:129
struct Hash * subj_hash
Hash table by subject.
Definition: mailbox.h:128
void * edata
Driver-specific data.
Definition: email.h:106
#define mutt_error(...)
Definition: logging.h:84
unsigned int index
Definition: pop_private.h:71
FILE * fp
pointer to the message data
Definition: mx.h:85
int index
The absolute (unsorted) message number.
Definition: email.h:85
#define FREE(x)
Definition: memory.h:40
POP-specific email cache.
Definition: pop_private.h:69
POP-specific Account data -.
Definition: pop_private.h:78
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:588
struct HashElem * mutt_hash_insert(struct Hash *table, const char *strkey, void *data)
Add a new element to the Hash table (with string keys)
Definition: hash.c:351
int pop_reconnect(struct Mailbox *m)
reconnect and verify indexes if connection was lost
Definition: pop_lib.c:616
struct Envelope * mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed)
parses an RFC822 header
Definition: parse.c:1137
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: pop_lib.c:518
SecurityFlags crypt_query(struct Body *m)
Check out the type of encryption used.
Definition: crypt.c:700
void(* free_edata)(void **ptr)
Driver-specific data free function.
Definition: email.h:107
int msgno
Number displayed to the user.
Definition: email.h:86
static int fetch_message(const char *line, void *data)
write line to file - Implements pop_fetch_t
Definition: pop.c:158
+ Here is the call graph for this function:

◆ pop_msg_close()

static int pop_msg_close ( struct Mailbox m,
struct Message msg 
)
static

Close an email - Implements MxOps::msg_close()

Return values
0Success
EOFError, see errno

Definition at line 1206 of file pop.c.

1207 {
1208  return mutt_file_fclose(&msg->fp);
1209 }
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
FILE * fp
pointer to the message data
Definition: mx.h:85
+ Here is the call graph for this function:

◆ pop_msg_save_hcache()

static int pop_msg_save_hcache ( struct Mailbox m,
struct Email e 
)
static

Save message to the header cache - Implements MxOps::msg_save_hcache()

Definition at line 1214 of file pop.c.

1215 {
1216  int rc = 0;
1217 #ifdef USE_HCACHE
1218  struct PopAccountData *adata = pop_adata_get(m);
1219  struct PopEmailData *edata = e->edata;
1220  header_cache_t *hc = pop_hcache_open(adata, mailbox_path(m));
1221  rc = mutt_hcache_store(hc, edata->uid, strlen(edata->uid), e, 0);
1222  mutt_hcache_close(hc);
1223 #endif
1224 
1225  return rc;
1226 }
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox&#39;s path string.
Definition: mailbox.h:192
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: pop_lib.c:666
void mutt_hcache_close(header_cache_t *hc)
Multiplexor for StoreOps::close.
Definition: hcache.c:422
int mutt_hcache_store(header_cache_t *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
Definition: hcache.c:529
const char * uid
Definition: pop_private.h:107
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
POP-specific Email data -.
Definition: pop_private.h:105
static header_cache_t * pop_hcache_open(struct PopAccountData *adata, const char *path)
Open the header cache.
Definition: pop.c:357
void * edata
Driver-specific data.
Definition: email.h:106
POP-specific Account data -.
Definition: pop_private.h:78
header cache structure
Definition: lib.h:83
+ Here is the call graph for this function:

◆ pop_path_probe()

enum MailboxType pop_path_probe ( const char *  path,
const struct stat *  st 
)

Is this a POP Mailbox? - Implements MxOps::path_probe()

Definition at line 1231 of file pop.c.

1232 {
1233  if (!path)
1234  return MUTT_UNKNOWN;
1235 
1236  if (mutt_str_startswith(path, "pop://", CASE_IGNORE))
1237  return MUTT_POP;
1238 
1239  if (mutt_str_startswith(path, "pops://", CASE_IGNORE))
1240  return MUTT_POP;
1241 
1242  return MUTT_UNKNOWN;
1243 }
Mailbox wasn&#39;t recognised.
Definition: mailbox.h:47
&#39;POP3&#39; Mailbox type
Definition: mailbox.h:55
Ignore case when comparing strings.
Definition: string2.h:68
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
char * path
Path of Email (for local Mailboxes)
Definition: email.h:91
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pop_path_canon()

static int pop_path_canon ( char *  buf,
size_t  buflen 
)
static

Canonicalise a Mailbox path - Implements MxOps::path_canon()

Definition at line 1248 of file pop.c.

1249 {
1250  if (!buf)
1251  return -1;
1252 
1253  return 0;
1254 }

◆ pop_path_pretty()

static int pop_path_pretty ( char *  buf,
size_t  buflen,
const char *  folder 
)
static

Abbreviate a Mailbox path - Implements MxOps::path_pretty()

Definition at line 1259 of file pop.c.

1260 {
1261  /* Succeed, but don't do anything, for now */
1262  return 0;
1263 }

◆ pop_path_parent()

static int pop_path_parent ( char *  buf,
size_t  buflen 
)
static

Find the parent of a Mailbox path - Implements MxOps::path_parent()

Definition at line 1268 of file pop.c.

1269 {
1270  /* Succeed, but don't do anything, for now */
1271  return 0;
1272 }

Variable Documentation

◆ C_PopCheckinterval

short C_PopCheckinterval

Config: (pop) Interval between checks for new mail.

Definition at line 67 of file pop.c.

◆ C_PopDelete

unsigned char C_PopDelete

Config: (pop) After downloading POP messages, delete them on the server.

Definition at line 71 of file pop.c.

◆ C_PopHost

char* C_PopHost

Config: (pop) Url of the POP server.

Definition at line 72 of file pop.c.

◆ C_PopLast

bool C_PopLast

Config: (pop) Use the 'LAST' command to fetch new mail.

Definition at line 73 of file pop.c.

◆ MxPopOps

struct MxOps MxPopOps
Initial value:
= {
.type = MUTT_POP,
.name = "pop",
.is_local = false,
.ac_find = pop_ac_find,
.ac_add = pop_ac_add,
.mbox_open = pop_mbox_open,
.mbox_open_append = NULL,
.mbox_check = pop_mbox_check,
.mbox_check_stats = NULL,
.mbox_sync = pop_mbox_sync,
.mbox_close = pop_mbox_close,
.msg_open = pop_msg_open,
.msg_open_new = NULL,
.msg_commit = NULL,
.msg_close = pop_msg_close,
.msg_padding_size = NULL,
.msg_save_hcache = pop_msg_save_hcache,
.tags_edit = NULL,
.tags_commit = NULL,
.path_probe = pop_path_probe,
.path_canon = pop_path_canon,
.path_pretty = pop_path_pretty,
.path_parent = pop_path_parent,
}
static int pop_mbox_check(struct Mailbox *m, int *index_hint)
Check for new mail - Implements MxOps::mbox_check()
Definition: pop.c:885
static int pop_path_pretty(char *buf, size_t buflen, const char *folder)
Abbreviate a Mailbox path - Implements MxOps::path_pretty()
Definition: pop.c:1259
static int pop_msg_open(struct Mailbox *m, struct Message *msg, int msgno)
Open an email message in a Mailbox - Implements MxOps::msg_open()
Definition: pop.c:1046
static int pop_path_parent(char *buf, size_t buflen)
Find the parent of a Mailbox path - Implements MxOps::path_parent()
Definition: pop.c:1268
static int pop_mbox_sync(struct Mailbox *m, int *index_hint)
Save changes to the Mailbox - Implements MxOps::mbox_sync()
Definition: pop.c:926
static struct Account * pop_ac_find(struct Account *a, const char *path)
Find an Account that matches a Mailbox path - Implements MxOps::ac_find()
Definition: pop.c:749
static int pop_mbox_close(struct Mailbox *m)
Close a Mailbox - Implements MxOps::mbox_close()
Definition: pop.c:1016
&#39;POP3&#39; Mailbox type
Definition: mailbox.h:55
static int pop_mbox_open(struct Mailbox *m)
Open a Mailbox - Implements MxOps::mbox_open()
Definition: pop.c:808
static int pop_path_canon(char *buf, size_t buflen)
Canonicalise a Mailbox path - Implements MxOps::path_canon()
Definition: pop.c:1248
enum MailboxType pop_path_probe(const char *path, const struct stat *st)
Is this a POP Mailbox? - Implements MxOps::path_probe()
Definition: pop.c:1231
static int pop_msg_close(struct Mailbox *m, struct Message *msg)
Close an email - Implements MxOps::msg_close()
Definition: pop.c:1206
static int pop_msg_save_hcache(struct Mailbox *m, struct Email *e)
Save message to the header cache - Implements MxOps::msg_save_hcache()
Definition: pop.c:1214
static int pop_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Implements MxOps::ac_add()
Definition: pop.c:774

POP Mailbox - Implements MxOps.

Definition at line 1278 of file pop.c.