NeoMutt  2021-10-29-43-g6b8931
Teaching an old dog new tricks
DOXYGEN
POP Response Parser API

Prototype for a function to handle POP server responses. More...

Functions

static int fetch_capa (const char *line, void *data)
 Parse CAPA output - Implements pop_fetch_t -. More...
 
static int fetch_auth (const char *line, void *data)
 Fetch list of the authentication mechanisms - Implements pop_fetch_t -. More...
 
static int check_uidl (const char *line, void *data)
 Find message with this UIDL and set refno - Implements pop_fetch_t -. More...
 
static int fetch_message (const char *line, void *data)
 Write line to file - Implements pop_fetch_t -. More...
 
static int fetch_uidl (const char *line, void *data)
 Parse UIDL - Implements pop_fetch_t -. More...
 

Detailed Description

Prototype for a function to handle POP server responses.

Parameters
strString to parse
dataPrivate data passed to pop_fetch_data()
Return values
0Success
-1Failure

Function Documentation

◆ fetch_capa()

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

Parse CAPA output - Implements pop_fetch_t -.

Parameters
lineList of capabilities
dataPOP data
Return values
0(always)

Definition at line 148 of file lib.c.

149 {
150  struct PopAccountData *adata = data;
151 
152  if (mutt_istr_startswith(line, "SASL"))
153  {
154  const char *c = mutt_str_skip_email_wsp(line + 4);
155  mutt_buffer_strcpy(&adata->auth_list, c);
156  }
157  else if (mutt_istr_startswith(line, "STLS"))
158  adata->cmd_stls = true;
159  else if (mutt_istr_startswith(line, "USER"))
160  adata->cmd_user = 1;
161  else if (mutt_istr_startswith(line, "UIDL"))
162  adata->cmd_uidl = 1;
163  else if (mutt_istr_startswith(line, "TOP"))
164  adata->cmd_top = 1;
165 
166  return 0;
167 }
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
Definition: string.c:587
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:170
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
POP-specific Account data -.
Definition: adata.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fetch_auth()

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

Fetch list of the authentication mechanisms - Implements pop_fetch_t -.

Parameters
lineList of authentication methods
dataPOP data
Return values
0(always)

Definition at line 175 of file lib.c.

176 {
177  struct PopAccountData *adata = data;
178 
179  if (!mutt_buffer_is_empty(&adata->auth_list))
180  {
181  mutt_buffer_addstr(&adata->auth_list, " ");
182  }
183  mutt_buffer_addstr(&adata->auth_list, line);
184 
185  return 0;
186 }
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_uidl()

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

Find message with this UIDL and set refno - Implements pop_fetch_t -.

Parameters
lineString containing UIDL
dataPOP data
Return values
0Success
-1Error

Definition at line 570 of file lib.c.

571 {
572  if (!line || !data)
573  return -1;
574 
575  char *endp = NULL;
576 
577  errno = 0;
578  unsigned int index = strtoul(line, &endp, 10);
579  if (errno != 0)
580  return -1;
581  while (*endp == ' ')
582  endp++;
583 
584  struct Mailbox *m = data;
585  for (int i = 0; i < m->msg_count; i++)
586  {
587  struct PopEmailData *edata = pop_edata_get(m->emails[i]);
588  if (mutt_str_equal(edata->uid, endp))
589  {
590  edata->refno = index;
591  break;
592  }
593  }
594 
595  return 0;
596 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:715
struct PopEmailData * pop_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:65
void * edata
Driver-specific data.
Definition: email.h:72
int index
The absolute (unsorted) message number.
Definition: email.h:110
A mailbox.
Definition: mailbox.h:82
int msg_count
Total number of messages.
Definition: mailbox.h:91
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
POP-specific Email data -.
Definition: edata.h:32
+ 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 98 of file pop.c.

99 {
100  FILE *fp = data;
101 
102  fputs(line, fp);
103  if (fputc('\n', fp) == EOF)
104  return -1;
105 
106  return 0;
107 }
+ 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 200 of file pop.c.

201 {
202  struct Mailbox *m = data;
203  struct PopAccountData *adata = pop_adata_get(m);
204  char *endp = NULL;
205 
206  errno = 0;
207  int index = strtol(line, &endp, 10);
208  if (errno)
209  return -1;
210  while (*endp == ' ')
211  endp++;
212  line = endp;
213 
214  /* uid must be at least be 1 byte */
215  if (strlen(line) == 0)
216  return -1;
217 
218  int i;
219  for (i = 0; i < m->msg_count; i++)
220  {
221  struct PopEmailData *edata = pop_edata_get(m->emails[i]);
222  if (mutt_str_equal(line, edata->uid))
223  break;
224  }
225 
226  if (i == m->msg_count)
227  {
228  mutt_debug(LL_DEBUG1, "new header %d %s\n", index, line);
229 
230  if (i >= m->email_max)
231  mx_alloc_memory(m);
232 
233  m->msg_count++;
234  m->emails[i] = email_new();
235 
236  m->emails[i]->edata = pop_edata_new(line);
238  }
239  else if (m->emails[i]->index != index - 1)
240  adata->clear_cache = true;
241 
242  m->emails[i]->index = index - 1;
243 
244  struct PopEmailData *edata = pop_edata_get(m->emails[i]);
245  edata->refno = index;
246 
247  return 0;
248 }
struct Email * email_new(void)
Create a new Email.
Definition: email.c:78
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
void mx_alloc_memory(struct Mailbox *m)
Create storage for the emails.
Definition: mx.c:1217
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:64
struct PopEmailData * pop_edata_new(const char *uid)
Create a new PopEmailData for an email.
Definition: edata.c:53
void pop_edata_free(void **ptr)
Free the private Email data - Implements Email::edata_free()
Definition: edata.c:41
void(* edata_free)(void **ptr)
Free the private data attached to the Email.
Definition: email.h:87
int email_max
Number of pointers in emails.
Definition: mailbox.h:100
bool clear_cache
Definition: adata.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function: