NeoMutt  2025-12-11-1039-g550ac6
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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 response - Implements pop_fetch_t -.
static int fetch_auth (const char *line, void *data)
 Parse AUTH response - Implements pop_fetch_t -.
static int check_uidl (const char *line, void *data)
 Parse UIDL response - Implements pop_fetch_t -.
static int fetch_message (const char *line, void *data)
 Parse a Message response - Implements pop_fetch_t -.
static int fetch_uidl (const char *line, void *data)
 Parse UIDL response - Implements pop_fetch_t -.

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()

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

Parse CAPA response - Implements pop_fetch_t -.

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

Definition at line 146 of file lib.c.

147{
148 struct PopAccountData *adata = data;
149
150 if (mutt_istr_startswith(line, "SASL"))
151 {
152 const char *c = mutt_str_skip_email_wsp(line + 4);
153 buf_strcpy(&adata->auth_list, c);
154 }
155 else if (mutt_istr_startswith(line, "STLS"))
156 {
157 adata->cmd_stls = true;
158 }
159 else if (mutt_istr_startswith(line, "USER"))
160 {
161 adata->cmd_user = 1;
162 }
163 else if (mutt_istr_startswith(line, "UIDL"))
164 {
165 adata->cmd_uidl = 1;
166 }
167 else if (mutt_istr_startswith(line, "TOP"))
168 {
169 adata->cmd_top = 1;
170 }
171
172 return 0;
173}
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition buffer.c:401
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
Definition string.c:614
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition string.c:246
void * adata
Private data (for Mailbox backends).
Definition account.h:42
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()

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

Parse AUTH response - Implements pop_fetch_t -.

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

Definition at line 181 of file lib.c.

182{
183 struct PopAccountData *adata = data;
184
185 if (!buf_is_empty(&adata->auth_list))
186 {
187 buf_addstr(&adata->auth_list, " ");
188 }
189 buf_addstr(&adata->auth_list, line);
190
191 return 0;
192}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:298
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:233
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_uidl()

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

Parse UIDL response - Implements pop_fetch_t -.

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

Find message with this UIDL and set refno.

Definition at line 576 of file lib.c.

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

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

Parse a Message response - Implements pop_fetch_t -.

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

Save a Message to a file.

Definition at line 102 of file pop.c.

103{
104 FILE *fp = data;
105
106 fputs(line, fp);
107 if (fputc('\n', fp) == EOF)
108 return -1;
109
110 return 0;
111}
Here is the caller graph for this function:

◆ fetch_uidl()

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

Parse UIDL response - Implements pop_fetch_t -.

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

Definition at line 214 of file pop.c.

215{
216 struct Mailbox *m = data;
218 char *endp = NULL;
219
220 errno = 0;
221 int index = strtol(line, &endp, 10);
222 if ((errno != 0) || (endp == line))
223 return -1;
224 while (*endp == ' ')
225 endp++;
226 line = endp;
227
228 /* uid must be at least be 1 byte */
229 if (strlen(line) == 0)
230 return -1;
231
232 int i;
233 for (i = 0; i < m->msg_count; i++)
234 {
235 struct PopEmailData *edata = pop_edata_get(m->emails[i]);
236 if (mutt_str_equal(line, edata->uid))
237 break;
238 }
239
240 if (i == m->msg_count)
241 {
242 if (m->msg_count >= POP_MAX_MESSAGES)
243 {
244 mutt_debug(LL_DEBUG1, "UIDL response limit reached (%d)\n", POP_MAX_MESSAGES);
245 return -1;
246 }
247
248 mutt_debug(LL_DEBUG1, "new header %d %s\n", index, line);
249
250 mx_alloc_memory(m, i);
251
252 m->msg_count++;
253 m->emails[i] = email_new();
254
255 m->emails[i]->edata = pop_edata_new(line);
257 }
258 else if (m->emails[i]->index != index - 1)
259 {
260 adata->clear_cache = true;
261 }
262
263 m->emails[i]->index = index - 1;
264
265 struct PopEmailData *edata = pop_edata_get(m->emails[i]);
266 edata->refno = index;
267
268 return 0;
269}
struct Email * email_new(void)
Create a new Email.
Definition email.c:77
void pop_edata_free(void **ptr)
Free the private Email data - Implements Email::edata_free() -.
Definition edata.c:41
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
@ LL_DEBUG1
Log at debug level 1.
Definition logging2.h:45
void mx_alloc_memory(struct Mailbox *m, int req_size)
Create storage for the emails.
Definition mx.c:1211
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition adata.c:73
struct PopEmailData * pop_edata_new(const char *uid)
Create a new PopEmailData for an email.
Definition edata.c:56
#define POP_MAX_MESSAGES
Hard limit on UIDL responses to prevent a malicious server from causing unbounded memory growth.
Definition pop.c:74
void(* edata_free)(void **ptr)
Definition email.h:90
bool clear_cache
Clear the cache.
Definition adata.h:49
Here is the call graph for this function:
Here is the caller graph for this function: