NeoMutt  2024-03-23-23-gec7045
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()

static 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 147 of file lib.c.

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

static 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 182 of file lib.c.

183{
184 struct PopAccountData *adata = data;
185
186 if (!buf_is_empty(&adata->auth_list))
187 {
188 buf_addstr(&adata->auth_list, " ");
189 }
190 buf_addstr(&adata->auth_list, line);
191
192 return 0;
193}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:308
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:243
+ 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

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 575 of file lib.c.

576{
577 if (!line || !data)
578 return -1;
579
580 char *endp = NULL;
581
582 errno = 0;
583 unsigned int index = strtoul(line, &endp, 10);
584 if (errno != 0)
585 return -1;
586 while (*endp == ' ')
587 endp++;
588
589 struct Mailbox *m = data;
590 for (int i = 0; i < m->msg_count; i++)
591 {
592 struct PopEmailData *edata = pop_edata_get(m->emails[i]);
593 if (mutt_str_equal(edata->uid, endp))
594 {
595 edata->refno = index;
596 break;
597 }
598 }
599
600 return 0;
601}
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:709
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:113
A mailbox.
Definition: mailbox.h:79
int msg_count
Total number of messages.
Definition: mailbox.h:88
struct Email ** emails
Array of Emails.
Definition: mailbox.h:96
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

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 99 of file pop.c.

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

◆ fetch_uidl()

static 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 202 of file pop.c.

203{
204 struct Mailbox *m = data;
206 char *endp = NULL;
207
208 errno = 0;
209 int index = strtol(line, &endp, 10);
210 if (errno)
211 return -1;
212 while (*endp == ' ')
213 endp++;
214 line = endp;
215
216 /* uid must be at least be 1 byte */
217 if (strlen(line) == 0)
218 return -1;
219
220 int i;
221 for (i = 0; i < m->msg_count; i++)
222 {
223 struct PopEmailData *edata = pop_edata_get(m->emails[i]);
224 if (mutt_str_equal(line, edata->uid))
225 break;
226 }
227
228 if (i == m->msg_count)
229 {
230 mutt_debug(LL_DEBUG1, "new header %d %s\n", index, line);
231
232 mx_alloc_memory(m, i);
233
234 m->msg_count++;
235 m->emails[i] = email_new();
236
237 m->emails[i]->edata = pop_edata_new(line);
239 }
240 else if (m->emails[i]->index != index - 1)
241 {
242 adata->clear_cache = true;
243 }
244
245 m->emails[i]->index = index - 1;
246
247 struct PopEmailData *edata = pop_edata_get(m->emails[i]);
248 edata->refno = index;
249
250 return 0;
251}
struct Email * email_new(void)
Create a new Email.
Definition: email.c:80
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:89
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
void mx_alloc_memory(struct Mailbox *m, int req_size)
Create storage for the emails.
Definition: mx.c:1204
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
void(* edata_free)(void **ptr)
Definition: email.h:90
bool clear_cache
Definition: adata.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function: