1 /*@ S-nail - a mail user agent derived from Berkeley Mail.
2 *@ Function prototypes and function-alike macros.
3 *@ TODO Should be split in myriads of FEATURE-GROUP.h headers.
4 *
5 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
6 * Copyright (c) 2012 - 2020 Steffen (Daode) Nurpmeso <steffen@sdaoden.eu>.
7 * SPDX-License-Identifier: BSD-3-Clause TODO ISC
8 */
9 /*
10 * Copyright (c) 1980, 1993
11 * The Regents of the University of California. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38 struct mx_attachment;
39 struct mx_cmd_arg;
40 struct su_cs_dict;
41 struct quoteflt;
42
43 /*
44 * TODO Convert optional utility+ functions to n_*(); ditto
45 * TODO else use generic module-specific prefixes: str_(), am[em]_, sm[em]_, ..
46 */
47 /* TODO s-it-mode: not really (docu, funnames, funargs, etc) */
48
49 #undef FL
50 #ifndef mx_HAVE_AMALGAMATION
51 # define FL extern
52 #else
53 # define FL static
54 #endif
55
56 /*
57 * Macro-based generics
58 */
59
60 /* RFC 822, 3.2. */
61 #define fieldnamechar(c) \
62 (su_cs_is_ascii(c) && (c) > 040 && (c) != 0177 && (c) != ':')
63
64 /* Single-threaded, use unlocked I/O */
65 #ifdef mx_HAVE_PUTC_UNLOCKED
66 # undef getc
67 # define getc(c) getc_unlocked(c)
68 # undef putc
69 # define putc(c, f) putc_unlocked(c, f)
70 #endif
71
72 /* There are problems with dup()ing of file-descriptors for child processes.
73 * We have to somehow accomplish that the FILE* fp makes itself comfortable
74 * with the *real* offset of the underlying file descriptor.
75 * POSIX Issue 7 overloaded fflush(3): if used on a readable stream, then
76 *
77 * if the file is not already at EOF, and the file is one capable of
78 * seeking, the file offset of the underlying open file description shall
79 * be set to the file position of the stream */
80 #if !su_OS_OPENBSD &&\
81 defined _POSIX_VERSION && _POSIX_VERSION + 0 >= 200809L
82 # define n_real_seek(FP,OFF,WH) (fseek(FP, OFF, WH) != -1 && fflush(FP) != EOF)
83 # define really_rewind(stream) \
84 do{\
85 rewind(stream);\
86 fflush(stream);\
87 }while(0)
88
89 #else
90 # define n_real_seek(FP,OFF,WH) \
91 (fseek(FP, OFF, WH) != -1 && fflush(FP) != EOF &&\
92 lseek(fileno(FP), OFF, WH) != -1)
93 # define really_rewind(stream) \
94 do{\
95 rewind(stream);\
96 fflush(stream);\
97 lseek(fileno(stream), 0, SEEK_SET);\
98 }while(0)
99 #endif
100
101 /* fflush() and rewind() */
102 #define fflush_rewind(stream) \
103 do{\
104 fflush(stream);\
105 rewind(stream);\
106 }while(0)
107
108 /* Truncate a file to the last character written. This is useful just before
109 * closing an old file that was opened for read/write */
110 #define ftrunc(stream) \
111 do{\
112 off_t off;\
113 fflush(stream);\
114 off = ftell(stream);\
115 if(off >= 0)\
116 ftruncate(fileno(stream), off);\
117 }while(0)
118
119 /*
120 * accmacvar.c
121 */
122
123 /* Macros: `define', `undefine', `call', `call_if' */
124 FL int c_define(void *v);
125 FL int c_undefine(void *v);
126 FL int c_call(void *v);
127 FL int c_call_if(void *v);
128
129 /* Accounts: `account', `unaccount' */
130 FL void mx_account_leave(void);
131 FL int c_account(void *v);
132 FL int c_unaccount(void *v);
133
134 /* `localopts', `shift', `return' */
135 FL int c_localopts(void *vp);
136 FL int c_shift(void *vp);
137 FL int c_return(void *vp);
138
139 /* TODO - Main loop on tick event: mx_sigs_all_holdx() is active
140 * TODO - main.c *on-program-exit*
141 * mac must not be NIL */
142 FL void temporary_on_xy_hook_caller(char const *hname, char const *mac,
143 boole sigs_held);
144
145 /* TODO Check whether a *folder-hook* exists for currently active mailbox */
146 FL boole temporary_folder_hook_check(boole nmail);
147 FL void temporary_folder_hook_unroll(void); /* XXX im. hack */
148
149 /* TODO v15 drop Invoke compose hook macname */
150 FL void temporary_compose_mode_hook_call(char const *macname,
151 void (*hook_pre)(void *), void *hook_arg);
152 FL void temporary_compose_mode_hook_unroll(void);
153
154 #ifdef mx_HAVE_HISTORY
155 /* TODO *on-history-addition* */
156 FL boole temporary_addhist_hook(char const *ctx, char const *gabby_type,
157 char const *histent);
158 #endif
159
160 /* TODO v15 drop: let shexp_parse_token take a carrier with positional
161 * TODO params, then let callers use that as such!!
162 * Call hook in a recursed environment named name where positional params are
163 * setup according to argv/argc. NOTE: all signals blocked! */
164 #ifdef mx_HAVE_REGEX
165 FL char *temporary_pospar_access_hook(char const *name, char const **argv,
166 u32 argc, char *(*hook)(void *uservp), void *uservp);
167 #endif
168
169 /* Setting up batch mode, variable-handling side */
170 FL void n_var_setup_batch_mode(void);
171
172 /* Can name freely be used as a variable by users? */
173 FL boole n_var_is_user_writable(char const *name);
174
175 /* Don't use n_var_* unless you *really* have to! */
176
177 /* Constant option key look/(un)set/clear */
178 FL char *n_var_oklook(enum okeys okey);
179 #define ok_blook(C) (n_var_oklook(su_CONCAT(ok_b_, C)) != NULL)
180 #define ok_vlook(C) n_var_oklook(su_CONCAT(ok_v_, C))
181
182 FL boole n_var_okset(enum okeys okey, up val);
183 #define ok_bset(C) \
184 n_var_okset(su_CONCAT(ok_b_, C), (up)TRU1)
185 #define ok_vset(C,V) \
186 n_var_okset(su_CONCAT(ok_v_, C), (up)(V))
187
188 FL boole n_var_okclear(enum okeys okey);
189 #define ok_bclear(C) n_var_okclear(su_CONCAT(ok_b_, C))
190 #define ok_vclear(C) n_var_okclear(su_CONCAT(ok_v_, C))
191
192 /* Variable option key lookup/(un)set/clear.
193 * If try_getenv is true we will getenv(3) _if_ vokey is not a known enum okey;
194 * it will also cause obsoletion messages only for doing lookup (once).
195 * _vexplode() is to be used by the shell expansion stuff when encountering
196 * ${@} in double-quotes, in order to provide sh(1)ell compatible behaviour;
197 * it returns whether there are any elements in argv (*cookie) */
198 FL char const *n_var_vlook(char const *vokey, boole try_getenv);
199 FL boole n_var_vexplode(void const **cookie);
200 FL boole n_var_vset(char const *vokey, up val);
201 FL boole n_var_vclear(char const *vokey);
202
203 /* Special case to handle the typical [xy-USER@HOST,] xy-HOST and plain xy
204 * variable chains; oxm is a bitmix which tells which combinations to test */
205 #ifdef mx_HAVE_NET
206 FL char *n_var_xoklook(enum okeys okey, struct mx_url const *urlp,
207 enum okey_xlook_mode oxm);
208 # define xok_BLOOK(C,URL,M) (n_var_xoklook(C, URL, M) != NULL)
209 # define xok_VLOOK(C,URL,M) n_var_xoklook(C, URL, M)
210 # define xok_blook(C,URL,M) xok_BLOOK(su_CONCAT(ok_b_, C), URL, M)
211 # define xok_vlook(C,URL,M) xok_VLOOK(su_CONCAT(ok_v_, C), URL, M)
212 #endif
213
214 /* User variable access: `set', `local' and `unset' */
215 FL int c_set(void *vp);
216 FL int c_unset(void *vp);
217
218 /* `varshow' */
219 FL int c_varshow(void *v);
220
221 /* `environ' */
222 FL int c_environ(void *v);
223
224 /* `vpospar' */
225 FL int c_vpospar(void *v);
226
227 /*
228 * auxlily.c
229 */
230
231 /* Compute *screen* size */
232 FL uz n_screensize(void);
233
234 /* In n_PSO_INTERACTIVE, we want to go over $PAGER.
235 * These are specialized version of fs_pipe_open()/fs_pipe_close() which also
236 * encapsulate error message printing, terminal handling etc. additionally */
237 FL FILE *mx_pager_open(void);
238 FL boole mx_pager_close(FILE *fp);
239
240 /* Use a pager or STDOUT to print *fp*; if *lines* is 0, they'll be counted */
241 FL void page_or_print(FILE *fp, uz lines);
242
243 /* Parse name and guess at the required protocol.
244 * If check_stat is true then stat(2) will be consulted - a TODO c..p hack
245 * TODO that together with *newfolders*=maildir adds Maildir support; sigh!
246 * If try_hooks is set check_stat is implied and if the stat(2) fails all
247 * file-hook will be tried in order to find a supported version of name.
248 * If adjusted_or_null is not NULL it will be set to the final version of name
249 * this function knew about: a %: FEDIT_SYSBOX prefix is forgotten, in case
250 * a hook is needed the "real" filename will be placed.
251 * TODO This c..p should be URL::from_string()->protocol() or something! */
252 FL enum protocol which_protocol(char const *name, boole check_stat,
253 boole try_hooks, char const **adjusted_or_null);
254
255 /* Hexadecimal itoa (NUL terminates) / atoi (-1 on error) */
256 FL char * n_c_to_hex_base16(char store[3], char c);
257 FL s32 n_c_from_hex_base16(char const hex[2]);
258
259 /* Return the name of the dead.letter file */
260 FL char const * n_getdeadletter(void);
261
262 /* Detect and query the hostname to use */
263 FL char *n_nodename(boole mayoverride);
264
265 /* Convert from / to *ttycharset* */
266 #ifdef mx_HAVE_IDNA
267 FL boole n_idna_to_ascii(struct n_string *out, char const *ibuf, uz ilen);
268 /*TODO FL boole n_idna_from_ascii(struct n_string *out, char const *ibuf,
269 uz ilen);*/
270 #endif
271
272 /* Check whether the argument string is a TRU1 or FAL0 boolean, or an invalid
273 * string, in which case TRUM1 is returned.
274 * If the input buffer is empty emptyrv is used as the return: if it is GE
275 * FAL0 it will be made a binary boolean, otherwise TRU2 is returned.
276 * inlen may be UZ_MAX to force su_cs_len() detection */
277 FL boole n_boolify(char const *inbuf, uz inlen, boole emptyrv);
278
279 /* Dig a "quadoption" in inbuf, possibly going through getapproval() in
280 * interactive mode, in which case prompt is printed first if set.
281 . Just like n_boolify() otherwise */
282 FL boole n_quadify(char const *inbuf, uz inlen, char const *prompt,
283 boole emptyrv);
284
285 /* Is the argument "all" (case-insensitive) or "*" */
286 FL boole n_is_all_or_aster(char const *name);
287
288 /* Get seconds since epoch, return pointer to static struct.
289 * Unless force_update is true we may use the event-loop tick time */
290 FL struct n_timespec const *n_time_now(boole force_update);
291 #define n_time_epoch() ((time_t)n_time_now(FAL0)->ts_sec)
292
293 /* Update *tc* to now; only .tc_time updated unless *full_update* is true */
294 FL void time_current_update(struct time_current *tc,
295 boole full_update);
296
297 /* TZ difference in seconds.
298 * secsepoch is only used if any of the tm's is NIL. */
299 FL s32 n_time_tzdiff(s64 secsepoch, struct tm const *utcp_or_nil,
300 struct tm const *localp_or_nil);
301
302 /* ctime(3), but do ensure 26 byte limit, do not crash XXX static buffer.
303 * NOTE: no trailing newline */
304 FL char *n_time_ctime(s64 secsepoch, struct tm const *localtime_or_nil);
305
306 /* Returns 0 if fully slept, number of millis left if ignint is true and we
307 * were interrupted. Actual resolution may be second or less.
308 * Note in case of mx_HAVE_SLEEP this may be SIGALARM based. */
309 FL uz n_msleep(uz millis, boole ignint);
310
311 /* Our error print series.. Note: these reverse scan format in order to know
312 * whether a newline was included or not -- this affects the output!
313 * xxx Prototype changes to be reflected in src/su/core-code. (for now) */
314 FL void n_err(char const *format, ...);
315 FL void n_errx(boole allow_multiple, char const *format, ...);
316 FL void n_verr(char const *format, va_list ap);
317 FL void n_verrx(boole allow_multiple, char const *format, va_list ap);
318
319 /* ..(for use in a signal handler; to be obsoleted..).. */
320 FL void n_err_sighdl(char const *format, ...);
321
322 /* Our perror(3); if errval is 0 su_err_no() is used; newline appended */
323 FL void n_perr(char const *msg, int errval);
324
325 /* Announce a fatal error (and die); newline appended */
326 FL void n_alert(char const *format, ...);
327 FL void n_panic(char const *format, ...);
328
329 /* `errors' */
330 #ifdef mx_HAVE_ERRORS
331 FL int c_errors(void *vp);
332 #endif
333
334 /* */
335 #ifdef mx_HAVE_REGEX
336 FL char const *n_regex_err_to_doc(const regex_t *rep, int e);
337 #endif
338
339 /* Shared code for c_unxy() which base upon su_cs_dict, e.g., `shortcut' */
340 FL su_boole mx_unxy_dict(char const *cmdname, struct su_cs_dict *dp, void *vp);
341
342 /* Sort all keys of dp, iterate over them, call the given hook ptf for each
343 * key/data pair, place any non-NIL returned in the *result list.
344 * A non-NIL *result will not be updated, but be appended to.
345 * tailpp_or_nil can be set to speed up follow runs.
346 * The boole return states error, *result may be NIL even upon success,
347 * e.g., if dp is NIL or empty */
348 FL boole mx_xy_dump_dict(char const *cmdname, struct su_cs_dict *dp,
349 struct n_strlist **result, struct n_strlist **tailpp_or_nil,
350 struct n_strlist *(*ptf)(char const *cmdname, char const *key,
351 void const *dat));
352
353 /* Default callback which can be used when dat is in fact a char const* */
354 FL struct n_strlist *mx_xy_dump_dict_gen_ptf(char const *cmdname,
355 char const *key, void const *dat);
356
357 /* page_or_print() all members of slp, one line per node.
358 * If slp is NIL print a line that no cmdname are registered.
359 * If cnt_lines is FAL0 then each slp entry is assumed to be one line without
360 * a trailing newline character, otherwise these characters are counted and
361 * a trailing such is put as necessary */
362 FL boole mx_page_or_print_strlist(char const *cmdname,
363 struct n_strlist *slp, boole cnt_lines);
364
365 /*
366 * cmd-cnd.c
367 */
368
369 /* if.elif.else.endif conditional execution */
370 FL int c_if(void *v);
371 FL int c_elif(void *v);
372 FL int c_else(void *v);
373 FL int c_endif(void *v);
374
375 /* Whether an `if' block exists (TRU1) / is in a whiteout condition (TRUM1) */
376 FL boole n_cnd_if_exists(void);
377
378 /* An execution context is teared down, and it finds to have an if stack */
379 FL void n_cnd_if_stack_del(struct n_go_data_ctx *gdcp);
380
381 /*
382 * cmd-folder.c
383 */
384
385 /* `file' (`folder') and `File' (`Folder') */
386 FL int c_file(void *v);
387 FL int c_File(void *v);
388
389 /* 'newmail' command: Check for new mail without writing old mail back */
390 FL int c_newmail(void *v);
391
392 /* noop */
393 FL int c_noop(void *v);
394
395 /* Remove mailbox */
396 FL int c_remove(void *v);
397
398 /* Rename mailbox */
399 FL int c_rename(void *v);
400
401 /* List the folders the user currently has */
402 FL int c_folders(void *v);
403
404 /*
405 * cmd-head.c
406 */
407
408 /* `headers' (show header group, possibly after setting dot) */
409 FL int c_headers(void *v);
410
411 /* Like c_headers(), but pre-prepared message vector */
412 FL int print_header_group(int *vector);
413
414 /* Scroll to the next/previous screen */
415 FL int c_scroll(void *v);
416 FL int c_Scroll(void *v);
417
418 /* Move the dot up or down by one message */
419 FL int c_dotmove(void *v);
420
421 /* Print out the headlines for each message in the passed message list */
422 FL int c_from(void *v);
423
424 /* Print all messages in msgvec visible and either only_marked is false or they
425 * are MMARKed.
426 * TODO If subject_thread_compress is true then a subject will not be printed
427 * TODO if it equals the subject of the message "above"; as this only looks
428 * TODO in the thread neighbour and NOT in the "visible" neighbour, the caller
429 * TODO has to ensure the result will look sane; DROP + make it work (tm) */
430 FL void print_headers(int const *msgvec, boole only_marked,
431 boole subject_thread_compress);
432
433 /*
434 * cmd-msg.c
435 */
436
437 /* Paginate messages, honour/don't honour ignored fields, respectively */
438 FL int c_more(void *v);
439 FL int c_More(void *v);
440
441 /* Type out messages, honour/don't honour ignored fields, respectively */
442 FL int c_type(void *v);
443 FL int c_Type(void *v);
444
445 /* Show raw message content */
446 FL int c_show(void *v);
447
448 /* `mimeview' */
449 FL int c_mimeview(void *vp);
450
451 /* Pipe messages, honour/don't honour ignored fields, respectively */
452 FL int c_pipe(void *vp);
453 FL int c_Pipe(void *vp);
454
455 /* Print the first *toplines* of each desired message */
456 FL int c_top(void *v);
457 FL int c_Top(void *v);
458
459 /* If any arguments were given, go to the next applicable argument following
460 * dot, otherwise, go to the next applicable message. If given as first
461 * command with no arguments, print first message */
462 FL int c_next(void *v);
463
464 /* `=': print out the value(s) of <msglist> (or dot) */
465 FL int c_pdot(void *vp);
466
467 /* Print the size of each message */
468 FL int c_messize(void *v);
469
470 /* Delete messages */
471 FL int c_delete(void *v);
472
473 /* Delete messages, then type the new dot */
474 FL int c_deltype(void *v);
475
476 /* Undelete the indicated messages */
477 FL int c_undelete(void *v);
478
479 /* Touch all the given messages so that they will get mboxed */
480 FL int c_stouch(void *v);
481
482 /* Make sure all passed messages get mboxed */
483 FL int c_mboxit(void *v);
484
485 /* Preserve messages, so that they will be sent back to the system mailbox */
486 FL int c_preserve(void *v);
487
488 /* Mark all given messages as unread */
489 FL int c_unread(void *v);
490
491 /* Mark all given messages as read */
492 FL int c_seen(void *v);
493
494 /* Message flag manipulation */
495 FL int c_flag(void *v);
496 FL int c_unflag(void *v);
497 FL int c_answered(void *v);
498 FL int c_unanswered(void *v);
499 FL int c_draft(void *v);
500 FL int c_undraft(void *v);
501
502 /*
503 * cmd-misc.c
504 */
505
506 /* `!': process a shell escape by saving signals, ignoring signals and sh -c */
507 FL int c_shell(void *v);
508
509 /* `shell': fork an interactive shell */
510 FL int c_dosh(void *v);
511
512 /* `cwd': print user's working directory */
513 FL int c_cwd(void *v);
514
515 /* `chdir': change user's working directory */
516 FL int c_chdir(void *v);
517
518 /* `echo' series: expand file names like echo (to stdout/stderr, with/out
519 * trailing newline) */
520 FL int c_echo(void *v);
521 FL int c_echoerr(void *v);
522 FL int c_echon(void *v);
523 FL int c_echoerrn(void *v);
524
525 /* `read', `readsh' */
526 FL int c_read(void *vp);
527 FL int c_readsh(void *vp);
528
529 /* `readall' */
530 FL int c_readall(void *vp);
531
532 /* `version', and generic support for the shared initial version line, which
533 * appends to sp the UA name, version etc., and a \n LF */
534 FL struct n_string *n_version(struct n_string *sp);
535 FL int c_version(void *vp);
536
537 /*
538 * cmd-resend.c
539 */
540
541 /* All thinkable sorts of `reply' / `respond' and `followup'.. */
542 FL int c_reply(void *vp);
543 FL int c_replyall(void *vp); /* v15-compat */
544 FL int c_replysender(void *vp); /* v15-compat */
545 FL int c_Reply(void *vp);
546 FL int c_followup(void *vp);
547 FL int c_followupall(void *vp); /* v15-compat */
548 FL int c_followupsender(void *vp); /* v15-compat */
549 FL int c_Followup(void *vp);
550
551 /* ..and a mailing-list reply and followup */
552 FL int c_Lreply(void *vp);
553 FL int c_Lfollowup(void *vp);
554
555 /* 'forward' / `Forward' */
556 FL int c_forward(void *vp);
557 FL int c_Forward(void *vp);
558
559 /* Resend a message list to a third person.
560 * The latter does not add the Resent-* header series */
561 FL int c_resend(void *vp);
562 FL int c_Resend(void *vp);
563
564 /*
565 * cmd-write.c
566 */
567
568 /* Save a message in a file. Mark the message as saved so we can discard when
569 * the user quits */
570 FL int c_save(void *vp);
571 FL int c_Save(void *vp);
572
573 /* Copy a message to a file without affected its saved-ness */
574 FL int c_copy(void *vp);
575 FL int c_Copy(void *vp);
576
577 /* Move a message to a file */
578 FL int c_move(void *vp);
579 FL int c_Move(void *vp);
580
581 /* Decrypt and copy a message to a file. Like plain `copy' at times */
582 FL int c_decrypt(void *vp);
583 FL int c_Decrypt(void *vp);
584
585 /* Write the indicated messages at the end of the passed file name, minus
586 * header and trailing blank line. This is the MIME save function */
587 FL int c_write(void *vp);
588
589 /*
590 * collect.c
591 */
592
593 /* temporary_compose_mode_hook_call() etc. setter hook */
594 FL void n_temporary_compose_hook_varset(void *arg);
595
596 /* If quotefile is (char*)-1, stdin will be used, caller has to verify that
597 * we're not running in interactive mode */
598 FL FILE *n_collect(enum n_mailsend_flags msf, struct header *hp,
599 struct message *mp, char const *quotefile, s8 *checkaddr_err);
600
601 /*
602 * folder.c
603 */
604
605 /* Set up editing on the given file name.
606 * If the first character of name is %, we are considered to be editing the
607 * file, otherwise we are reading our mail which has signficance for mbox and
608 * so forth */
609 FL int setfile(char const *name, enum fedit_mode fm);
610
611 FL int newmailinfo(int omsgCount);
612
613 /* Set the size of the message vector used to construct argument lists to
614 * message list functions */
615 FL void setmsize(int sz);
616
617 /* Logic behind -H / -L invocations */
618 FL void print_header_summary(char const *Larg);
619
620 /* Announces the current folder as indicated.
621 * Is responsible for updating "dot" (after a folder change). */
622 FL void n_folder_announce(enum n_announce_flags af);
623
624 FL int getmdot(int nmail);
625
626 FL void initbox(char const *name);
627
628 /* Determine and expand the current *folder* name, return it (with trailing
629 * solidus) or the empty string also in case of errors: since POSIX mandates
630 * a default of CWD if not set etc., that seems to be a valid fallback, then */
631 FL char const *n_folder_query(void);
632
633 /* Prepare the seekable O_APPEND MBOX fout for appending of another message.
634 * If st_or_null is not NULL it is assumed to point to an up-to-date status of
635 * fout, otherwise an internal fstat(2) is performed as necessary.
636 * Returns su_err_no() of error */
637 FL int n_folder_mbox_prepare_append(FILE *fout, struct stat *st_or_null);
638
639 /*
640 * go.c
641 * Program input of all sorts, input lexing, event loops, command evaluation.
642 * Also alias handling.
643 */
644
645 /* Setup the run environment; this i *only* for main() */
646 FL void n_go_init(void);
647
648 /* Interpret user commands. If stdin is not a tty, print no prompt; return
649 * whether last processed command returned error; this is *only* for main()! */
650 FL boole n_go_main_loop(void);
651
652 /* Actual cmd input */
653
654 /* */
655 FL void n_go_input_clearerr(void);
656
657 /* Force n_go_input() to read EOF next */
658 FL void n_go_input_force_eof(void);
659
660 /* Returns true if force_eof() has been set -- it is set automatically if
661 * an input context enters EOF state (rather than error, as in ferror(3)) */
662 FL boole n_go_input_is_eof(void);
663
664 /* Are there any go_input_inject()ions pending? */
665 FL boole n_go_input_have_injections(void);
666
667 /* Force n_go_input() to read that buffer next.
668 * If n_GO_INPUT_INJECT_COMMIT is not set the line editor is reentered with buf
669 * as the default/initial line content */
670 FL void n_go_input_inject(enum n_go_input_inject_flags giif, char const *buf,
671 uz len);
672
673 /* Read a complete line of input, with editing if interactive and possible.
674 * string_or_nil is the optional initial line content if in interactive
675 * mode, otherwise this argument is ignored for reproducibility.
676 * If histok_or_nil is set it will be updated to FAL0 if input shall not be
677 * placed in history.
678 * Return number of octets or a value <0 on error.
679 * Note: may use the currently `source'd file stream instead of stdin!
680 * Manages the n_PS_READLINE_NL hack
681 * TODO We need an OnReadLineCompletedEvent and drop this function */
682 FL int n_go_input(enum n_go_input_flags gif, char const *prompt_or_nil,
683 char **linebuf, uz *linesize, char const *string_or_nil,
684 boole *histok_or_nil su_DBG_LOC_ARGS_DECL);
685 #ifdef su_HAVE_DBG_LOC_ARGS
686 # define n_go_input(A,B,C,D,E,F) n_go_input(A,B,C,D,E,F su_DBG_LOC_ARGS_INJ)
687 #endif
688
689 /* Like go_input(), but return savestr()d result or NIL in case of errors or if
690 * an empty line would be returned.
691 * This may only be called from toplevel (not during n_PS_ROBOT) */
692 FL char *n_go_input_cp(enum n_go_input_flags gif, char const *prompt_or_nil,
693 char const *string_or_nil);
694
695 /* Deal with loading of resource files and dealing with a stack of files for
696 * the source command */
697
698 /* Load a file of user system startup resources.
699 * *Only* for main(), returns whether program shall continue */
700 FL boole n_go_load_rc(char const *name);
701
702 /* "Load" or go_inject() command line option "cmd" arguments in order.
703 * *Only* for main(), returns whether program shall continue unless injectit is
704 * set, in which case this function does not fail.
705 * If lines is NIL the builtin RC file is used, and errors are ignored */
706 FL boole n_go_load_lines(boole injectit, char const **lines, uz cnt);
707
708 /* Pushdown current input file and switch to a new one. */
709 FL int c_source(void *v);
710 FL int c_source_if(void *v);
711
712 /* Evaluate a complete macro / a single command. For the former lines will
713 * be free()d, for the latter cmd will always be duplicated internally */
714 FL boole n_go_macro(enum n_go_input_flags gif, char const *name, char **lines,
715 void (*on_finalize)(void*), void *finalize_arg);
716 FL boole n_go_command(enum n_go_input_flags gif, char const *cmd);
717
718 /* XXX See a_GO_SPLICE in source */
719 FL void n_go_splice_hack(char const *cmd, FILE *new_stdin, FILE *new_stdout,
720 u32 new_psonce, void (*on_finalize)(void*), void *finalize_arg);
721 FL void n_go_splice_hack_remove_after_jump(void);
722
723 /* XXX Hack: may we release our (interactive) (terminal) control to a different
724 * XXX program, e.g., a $PAGER? */
725 FL boole n_go_may_yield_control(void);
726
727 /* `eval' */
728 FL int c_eval(void *vp);
729
730 /* `xcall' */
731 FL int c_xcall(void *vp);
732
733 /* `exit' and `quit' commands */
734 FL int c_exit(void *vp);
735 FL int c_quit(void *vp);
736
737 /* `readctl' */
738 FL int c_readctl(void *vp);
739
740 /*
741 * header.c
742 */
743
744 /* Return the user's From: address(es) */
745 FL char const * myaddrs(struct header *hp);
746
747 /* Boil the user's From: addresses down to a single one, or use *sender* */
748 FL char const * myorigin(struct header *hp);
749
750 /* See if the passed line buffer, which may include trailing newline (sequence)
751 * is a mail From_ header line according to POSIX ("From ").
752 * If check_rfc4155 is true we'll return TRUM1 instead if the From_ line
753 * matches POSIX but is _not_ compatible to RFC 4155 */
754 FL boole is_head(char const *linebuf, uz linelen,
755 boole check_rfc4155);
756
757 /* Return pointer to first non-header, non-space character, or NIL if invalid.
758 * If lead_ws is true leading whitespace is allowed and skipped.
759 * If cramp_or_nil is not NIL it will be set to the valid header name itself */
760 FL char const *mx_header_is_valid(char const *name, boole lead_ws,
761 struct str *cramp_or_nil);
762
763 /* Print hp "to user interface" fp for composing purposes xxx what a sigh */
764 FL boole n_header_put4compose(FILE *fp, struct header *hp);
765
766 /* Extract some header fields (see e.g. -t documentation) from a message.
767 * This calls expandaddr() on some headers and sets checkaddr_err_or_null if
768 * that is set -- note it explicitly allows EAF_NAME because aliases are not
769 * expanded when this is called! */
770 FL void n_header_extract(enum n_header_extract_flags hef, FILE *fp,
771 struct header *hp, s8 *checkaddr_err_or_null);
772
773 /* Return the desired header line from the passed message
774 * pointer (or NULL if the desired header field is not available).
775 * If mult is zero, return the content of the first matching header
776 * field only, the content of all matching header fields else */
777 FL char * hfield_mult(char const *field, struct message *mp, int mult);
778 #define hfieldX(a, b) hfield_mult(a, b, 1)
779 #define hfield1(a, b) hfield_mult(a, b, 0)
780
781 /* Check whether the passed line is a header line of the desired breed.
782 * If qm_suffix_or_nil is set then the field?[MOD]: syntax is supported, the
783 * suffix substring range of linebuf will be stored in there, then, or NIL;
784 * this logically casts away the const.
785 * Return the field body, or NULL */
786 FL char const *n_header_get_field(char const *linebuf, char const *field,
787 struct str *qm_suffix_or_nil);
788
789 /* Start of a "comment". Ignore it */
790 FL char const * skip_comment(char const *cp);
791
792 /* Return the start of a route-addr (address in angle brackets), if present */
793 FL char const * routeaddr(char const *name);
794
795 /* Query *expandaddr*, parse it and return flags.
796 * Flags are already adjusted for n_PSO_INTERACTIVE, n_PO_TILDE_FLAG etc. */
797 FL enum expand_addr_flags expandaddr_to_eaf(void);
798
799 /* Check if an address is invalid, either because it is malformed or, if not,
800 * according to eacm. Return FAL0 when it looks good, TRU1 if it is invalid
801 * but the error condition was not covered by a 'hard "fail"ure', else -1 */
802 FL s8 is_addr_invalid(struct mx_name *np,
803 enum expand_addr_check_mode eacm);
804
805 /* Does *NP* point to a file or pipe addressee? */
806 #define is_fileorpipe_addr(NP) \
807 (((NP)->n_flags & mx_NAME_ADDRSPEC_ISFILEORPIPE) != 0)
808
809 /* Skin an address according to the RFC 822 interpretation of "host-phrase" */
810 FL char * skin(char const *name);
811
812 /* Skin *name* and extract *addr-spec* according to RFC 5322 and enum gfield.
813 * Store the result in .ag_skinned and also fill in those .ag_ fields that have
814 * actually been seen.
815 * Return NULL on error, or name again, but which may have been replaced by
816 * a version with fixed quotation etc.! */
817 FL char const *n_addrspec_with_guts(struct n_addrguts *agp, char const *name,
818 u32 gfield);
819
820 /* `addrcodec' */
821 FL int c_addrcodec(void *vp);
822
823 /* Fetch the real name from an internet mail address field */
824 FL char * realname(char const *name);
825
826 /* Look for a RFC 2369 List-Post: header, return NIL if none was found, -1 if
827 * the one found forbids posting to the list, a header otherwise.
828 * .n_type needs to be set to something desired still */
829 FL struct mx_name *mx_header_list_post_of(struct message *mp);
830
831 /* Get the sender (From: or Sender:) of this message, or NIL.
832 * If gf is 0 GFULL|GSKIN is used (no senderfield beside that) */
833 FL struct mx_name *mx_header_sender_of(struct message *mp, u32 gf);
834
835 /* Get header_sender_of(), or From_ line from this message.
836 * The return value may be empty and needs lextract()ion */
837 FL char *n_header_senderfield_of(struct message *mp);
838
839 /* Trim away all leading Re: etc., return pointer to plain subject.
840 * Note it doesn't perform any MIME decoding by itself */
841 FL char const *subject_re_trim(char const *cp);
842
843 FL int msgidcmp(char const *s1, char const *s2);
844
845 /* Fake Sender for From_ lines if missing, e. g. with POP3 */
846 FL char const * fakefrom(struct message *mp);
847
848 /* From username Fri Jan 2 20:13:51 2004
849 * | | | | |
850 * 0 5 10 15 20 */
851 #if defined mx_HAVE_IMAP_SEARCH || defined mx_HAVE_IMAP
852 FL time_t unixtime(char const *from);
853 #endif
854
855 FL time_t rfctime(char const *date);
856
857 FL time_t combinetime(int year, int month, int day,
858 int hour, int minute, int second);
859
860 /* Determine the date to print in faked 'From ' lines */
861 FL void substdate(struct message *m);
862
863 /* Create ready-to-go environment taking into account *datefield* etc.,
864 * and return a result in auto-reclaimed storage.
865 * TODO hack *color_tag_or_null could be set to n_COLOUR_TAG_SUM_OLDER.
866 * time_current is used for comparison and must thus be up-to-date */
867 FL char *n_header_textual_date_info(struct message *mp,
868 char const **color_tag_or_null);
869
870 /* Create ready-to-go sender name of a message in *cumulation_or_null, the
871 * addresses only in *addr_or_null, the real names only in *name_real_or_null,
872 * and the full names in *name_full_or_null, taking account for *showname*.
873 * If *is_to_or_null is set, *showto* and n_is_myname() are taken into account
874 * when choosing which names to use.
875 * The list as such is returned, or NULL if there is really none (empty strings
876 * will be stored, then).
877 * All results are in auto-reclaimed storage, but may point to the same string.
878 * TODO *is_to_or_null could be set to whether we actually used To:, or not.
879 * TODO n_header_textual_sender_info(): should only create a list of matching
880 * TODO name objects, which the user can iterate over and o->to_str().. */
881 FL struct mx_name *n_header_textual_sender_info(struct message *mp,
882 char **cumulation_or_null, char **addr_or_null,
883 char **name_real_or_null, char **name_full_or_null,
884 boole *is_to_or_null);
885
886 /* TODO Weird thing that tries to fill in From: and Sender: */
887 FL void setup_from_and_sender(struct header *hp);
888
889 /* Note: returns 0x1 if both args were NULL */
890 FL struct mx_name const *check_from_and_sender(struct mx_name const *fromfield,
891 struct mx_name const *senderfield);
892
893 #ifdef mx_HAVE_XTLS
894 FL char * getsender(struct message *m);
895 #endif
896
897 /* This returns NULL if hp is NULL or when no information is available.
898 * hp remains unchanged (->h_in_reply_to is not set!) */
899 FL struct mx_name *n_header_setup_in_reply_to(struct header *hp);
900
901 /* Fill in / reedit the desired header fields */
902 FL int grab_headers(enum n_go_input_flags gif, struct header *hp,
903 enum gfield gflags, int subjfirst);
904
905 /* Check whether sep->ss_sexpr (or ->ss_sregex) matches any header of mp.
906 * If sep->s_where (or >s_where_wregex) is set, restrict to given headers */
907 FL boole n_header_match(struct message *mp, struct search_expr const *sep);
908
909 /* Verify whether len (UZ_MAX=su_cs_len) bytes of name form a standard or
910 * otherwise known header name (that must not be used as a custom header).
911 * Return the (standard) header name, or NULL */
912 FL char const *n_header_is_known(char const *name, uz len);
913
914 /* Add a custom header to the given list, in auto-reclaimed or heap memory */
915 FL boole n_header_add_custom(struct n_header_field **hflp, char const *dat,
916 boole heap);
917
918 /*
919 * ignore.c
920 */
921
922 /* `(un)?headerpick' */
923 FL int c_headerpick(void *vp);
924 FL int c_unheaderpick(void *vp);
925
926 /* TODO Compat variants of the c_(un)?h*() series,
927 * except for `retain' and `ignore', which are standardized */
928 FL int c_retain(void *vp);
929 FL int c_ignore(void *vp);
930 FL int c_unretain(void *vp);
931 FL int c_unignore(void *vp);
932
933 FL int c_saveretain(void *v);
934 FL int c_saveignore(void *v);
935 FL int c_unsaveretain(void *v);
936 FL int c_unsaveignore(void *v);
937
938 FL int c_fwdretain(void *v);
939 FL int c_fwdignore(void *v);
940 FL int c_unfwdretain(void *v);
941 FL int c_unfwdignore(void *v);
942
943 /* Ignore object lifecycle. (Most of the time this interface deals with
944 * special n_IGNORE_* objects, e.g., n_IGNORE_TYPE, though.)
945 * isauto: whether auto-reclaimed storage is to be used for allocations;
946 * if so, _del() needn't be called */
947 FL struct n_ignore *n_ignore_new(boole isauto);
948 FL void n_ignore_del(struct n_ignore *self);
949
950 /* Are there just _any_ user settings covered by self? */
951 FL boole n_ignore_is_any(struct n_ignore const *self);
952
953 /* Set an entry to retain (or ignore).
954 * Returns FAL0 if dat is not a valid header field name or an invalid regular
955 * expression, TRU1 if insertion took place, and TRUM1 if already set */
956 FL boole n_ignore_insert(struct n_ignore *self, boole retain,
957 char const *dat, uz len);
958 #define n_ignore_insert_cp(SELF,RT,CP) n_ignore_insert(SELF, RT, CP, UZ_MAX)
959
960 /* Returns TRU1 if retained, TRUM1 if ignored, FAL0 if not covered */
961 FL boole n_ignore_lookup(struct n_ignore const *self, char const *dat,
962 uz len);
963 #define n_ignore_lookup_cp(SELF,CP) n_ignore_lookup(SELF, CP, UZ_MAX)
964 #define n_ignore_is_ign(SELF,FDAT,FLEN) \
965 (n_ignore_lookup(SELF, FDAT, FLEN) == TRUM1)
966
967 /*
968 * imap-search.c
969 */
970
971 /* Return -1 on invalid spec etc., the number of matches otherwise */
972 #ifdef mx_HAVE_IMAP_SEARCH
973 FL sz imap_search(char const *spec, int f);
974 #endif
975
976 /*
977 * maildir.c
978 */
979
980 #ifdef mx_HAVE_MAILDIR
981 FL int maildir_setfile(char const *who, char const *name, enum fedit_mode fm);
982
983 FL boole maildir_quit(boole hold_sigs_on);
984
985 FL enum okay maildir_append(char const *name, FILE *fp, long offset);
986
987 FL enum okay maildir_remove(char const *name);
988 #endif /* mx_HAVE_MAILDIR */
989
990 /*
991 * (Former memory.c, now SU TODO get rid of compat macros)
992 * Heap memory and automatically reclaimed storage, plus pseudo "alloca"
993 *
994 */
995
996 /* Generic heap memory */
997 #define n_alloc su_MEM_ALLOC
998 #define n_realloc su_MEM_REALLOC
999 #define n_calloc(NO,SZ) su_MEM_CALLOC_N(SZ, NO)
1000 #define n_free su_MEM_FREE
1001
1002 /* Auto-reclaimed storage */
1003 #define n_autorec_relax_create() \
1004 su_mem_bag_auto_relax_create(n_go_data->gdc_membag)
1005 #define n_autorec_relax_gut() \
1006 su_mem_bag_auto_relax_gut(n_go_data->gdc_membag)
1007 #define n_autorec_relax_unroll() \
1008 su_mem_bag_auto_relax_unroll(n_go_data->gdc_membag)
1009 /* (Even older obsolete names!) */
1010 #define srelax_hold n_autorec_relax_create
1011 #define srelax_rele n_autorec_relax_gut
1012 #define srelax n_autorec_relax_unroll
1013
1014 #define n_autorec_alloc su_MEM_BAG_SELF_AUTO_ALLOC
1015 #define n_autorec_calloc(NO,SZ) su_MEM_BAG_SELF_AUTO_CALLOC_N(SZ, NO)
1016
1017 /* Pseudo alloca (and also auto-reclaimed) */
1018 #define n_lofi_alloc su_MEM_BAG_SELF_LOFI_ALLOC
1019 #define n_lofi_calloc su_MEM_BAG_SELF_LOFI_CALLOC
1020 #define n_lofi_free su_MEM_BAG_SELF_LOFI_FREE
1021
1022 #define n_lofi_snap_create() su_mem_bag_lofi_snap_create(n_go_data->gdc_membag)
1023 #define n_lofi_snap_unroll(COOKIE) \
1024 su_mem_bag_lofi_snap_unroll(n_go_data->gdc_membag, COOKIE)
1025
1026 /*
1027 * message.c
1028 */
1029
1030 /* Return a file buffer all ready to read up the passed message pointer */
1031 FL FILE * setinput(struct mailbox *mp, struct message *m,
1032 enum needspec need);
1033
1034 /* */
1035 FL enum okay get_body(struct message *mp);
1036
1037 /* Reset (free) the global message array */
1038 FL void message_reset(void);
1039
1040 /* Append the passed message descriptor onto the message array; if mp is NULL,
1041 * NULLify the entry at &[msgCount-1] */
1042 FL void message_append(struct message *mp);
1043
1044 /* Append a NULL message */
1045 FL void message_append_null(void);
1046
1047 /* Check whether sep->ss_sexpr (or ->ss_sregex) matches mp. If with_headers is
1048 * true then the headers will also be searched (as plain text) */
1049 FL boole message_match(struct message *mp, struct search_expr const *sep,
1050 boole with_headers);
1051
1052 /* */
1053 FL struct message * setdot(struct message *mp);
1054
1055 /* Touch the named message by setting its MTOUCH flag. Touched messages have
1056 * the effect of not being sent back to the system mailbox on exit */
1057 FL void touch(struct message *mp);
1058
1059 /* Convert user message spec. to message numbers and store them in vector,
1060 * which should be capable to hold msgCount+1 entries (n_msgvec ASSERTs this).
1061 * flags is cmd_arg_ctx.cac_msgflag==cmd_desc.cd_mflags_o_minargs==enum mflag.
1062 * If capp_or_null is not NULL then the last (string) token is stored in here
1063 * and not interpreted as a message specification; in addition, if only one
1064 * argument remains and this is the empty string, 0 is returned (*vector=0;
1065 * this is used to implement CMD_ARG_DESC_MSGLIST_AND_TARGET).
1066 * A NUL *buf input results in a 0 return, *vector=0, [*capp_or_null=NULL].
1067 * Returns the count of messages picked up or -1 on error */
1068 FL int n_getmsglist(char const *buf, int *vector, int flags,
1069 struct mx_cmd_arg **capp_or_null);
1070
1071 /* Find the first message whose flags&m==f and return its message number */
1072 FL int first(int f, int m);
1073
1074 /* Mark the named message by setting its mark bit */
1075 FL void mark(int mesg, int f);
1076
1077 /*
1078 * mime.c
1079 */
1080
1081 /* *sendcharsets* .. *charset-8bit* iterator; *a_charset_to_try_first* may be
1082 * used to prepend a charset to this list (e.g., for *reply-in-same-charset*).
1083 * The returned boolean indicates charset_iter_is_valid().
1084 * Without mx_HAVE_ICONV, this "iterates" over *ttycharset* only */
1085 FL boole charset_iter_reset(char const *a_charset_to_try_first);
1086 FL boole charset_iter_next(void);
1087 FL boole charset_iter_is_valid(void);
1088 FL char const * charset_iter(void);
1089
1090 /* And this is (xxx temporary?) which returns the iterator if that is valid and
1091 * otherwise either *charset-8bit* or *ttycharset*, dep. on mx_HAVE_ICONV */
1092 FL char const * charset_iter_or_fallback(void);
1093
1094 FL void charset_iter_recurse(char *outer_storage[2]); /* TODO LEGACY */
1095 FL void charset_iter_restore(char *outer_storage[2]); /* TODO LEGACY */
1096
1097 /* Check whether our headers will need MIME conversion */
1098 #ifdef mx_HAVE_ICONV
1099 FL char const * need_hdrconv(struct header *hp);
1100 #endif
1101
1102 /* Convert header fields from RFC 1522 format */
1103 FL void mime_fromhdr(struct str const *in, struct str *out,
1104 enum tdflags flags);
1105
1106 /* Interpret MIME strings in parts of an address field */
1107 FL char * mime_fromaddr(char const *name);
1108
1109 /* fwrite(3) performing the given MIME conversion */
1110 FL sz mime_write(char const *ptr, uz size, FILE *f,
1111 enum conversion convert, enum tdflags dflags,
1112 struct quoteflt *qf, struct str *outrest,
1113 struct str *inrest);
1114 FL sz xmime_write(char const *ptr, uz size, /* TODO LEGACY */
1115 FILE *f, enum conversion convert, enum tdflags dflags,
1116 struct str *outrest, struct str *inrest);
1117
1118 /*
1119 * mime-enc.c
1120 * Content-Transfer-Encodings as defined in RFC 2045 (and RFC 2047):
1121 * - Quoted-Printable, section 6.7
1122 * - Base64, section 6.8
1123 * TODO For now this is pretty mixed up regarding this external interface
1124 * TODO (and due to that the code is, too).
1125 * TODO In v15.0 CTE will be filter based, and explicit conversion will
1126 * TODO gain clear error codes
1127 */
1128
1129 /* Default MIME Content-Transfer-Encoding: as via *mime-encoding*.
1130 * Cannot be MIMEE_BIN nor MIMEE_7B (i.e., only B64, QP, 8B) */
1131 FL enum mime_enc mime_enc_target(void);
1132
1133 /* Map from a Content-Transfer-Encoding: header body (which may be NULL) */
1134 FL enum mime_enc mime_enc_from_ctehead(char const *hbody);
1135
1136 /* XXX Try to get rid of that */
1137 FL char const * mime_enc_from_conversion(enum conversion const convert);
1138
1139 /* How many characters of (the complete body) ln need to be quoted.
1140 * Only MIMEEF_ISHEAD and MIMEEF_ISENCWORD are understood */
1141 FL uz mime_enc_mustquote(char const *ln, uz lnlen,
1142 enum mime_enc_flags flags);
1143
1144 /* How much space is necessary to encode len bytes in QP, worst case.
1145 * Includes room for terminator, UZ_MAX on overflow */
1146 FL uz qp_encode_calc_size(uz len);
1147
1148 /* If flags includes QP_ISHEAD these assume "word" input and use special
1149 * quoting rules in addition; soft line breaks are not generated.
1150 * Otherwise complete input lines are assumed and soft line breaks are
1151 * generated as necessary. Return NULL on error (overflow) */
1152 FL struct str * qp_encode(struct str *out, struct str const *in,
1153 enum qpflags flags);
1154 #ifdef notyet
1155 FL struct str * qp_encode_cp(struct str *out, char const *cp,
1156 enum qpflags flags);
1157 FL struct str * qp_encode_buf(struct str *out, void const *vp, uz vp_len,
1158 enum qpflags flags);
1159 #endif
1160
1161 /* The buffers of out and *rest* will be managed via n_realloc().
1162 * If inrest_or_null is needed but NULL an error occurs, otherwise tolerant.
1163 * Return FAL0 on error; caller is responsible to free buffers */
1164 FL boole qp_decode_header(struct str *out, struct str const *in);
1165 FL boole qp_decode_part(struct str *out, struct str const *in,
1166 struct str *outrest, struct str *inrest_or_null);
1167
1168 /* How much space is necessary to encode len bytes in Base64, worst case.
1169 * Includes room for (CR/LF/CRLF and) terminator, UZ_MAX on overflow */
1170 FL uz b64_encode_calc_size(uz len);
1171
1172 /* Note these simply convert all the input (if possible), including the
1173 * insertion of NL sequences if B64_CRLF or B64_LF is set (and multiple thereof
1174 * if B64_MULTILINE is set).
1175 * Thus, in the B64_BUF case, better call b64_encode_calc_size() first.
1176 * Return NULL on error (overflow; cannot happen for B64_BUF) */
1177 FL struct str * b64_encode(struct str *out, struct str const *in,
1178 enum b64flags flags);
1179 FL struct str * b64_encode_buf(struct str *out, void const *vp, uz vp_len,
1180 enum b64flags flags);
1181 #ifdef notyet
1182 FL struct str * b64_encode_cp(struct str *out, char const *cp,
1183 enum b64flags flags);
1184 #endif
1185
1186 /* The _{header,part}() variants are failure tolerant, the latter requires
1187 * outrest to be set; due to the odd 4:3 relation inrest_or_null should be
1188 * given, _then_, it is an error if it is needed but not set.
1189 * TODO pre v15 callers should ensure that no endless loop is entered because
1190 * TODO the inrest cannot be converted and ends up as inrest over and over:
1191 * TODO give NULL to stop such loops.
1192 * The buffers of out and possibly *rest* will be managed via n_realloc().
1193 * Returns FAL0 on error; caller is responsible to free buffers.
1194 * XXX FAL0 is effectively not returned for _part*() variants,
1195 * XXX (instead replacement characters are produced for invalid data.
1196 * XXX _Unless_ operation could EOVERFLOW.)
1197 * XXX I.e. this is bad and is tolerant for text and otherwise not */
1198 FL boole b64_decode(struct str *out, struct str const *in);
1199 FL boole b64_decode_header(struct str *out, struct str const *in);
1200 FL boole b64_decode_part(struct str *out, struct str const *in,
1201 struct str *outrest, struct str *inrest_or_null);
1202
1203 /*
1204 * mime-param.c
1205 */
1206
1207 /* Get a mime style parameter from a header body */
1208 FL char * mime_param_get(char const *param, char const *headerbody);
1209
1210 /* Format parameter name to have value, autorec_alloc() it or NULL in result.
1211 * 0 on error, 1 or -1 on success: the latter if result contains \n newlines,
1212 * which it will if the created param requires more than MIME_LINELEN bytes;
1213 * there is never a trailing newline character */
1214 /* TODO mime_param_create() should return a StrList<> or something.
1215 * TODO in fact it should take a HeaderField* and append HeaderFieldParam*! */
1216 FL s8 mime_param_create(struct str *result, char const *name,
1217 char const *value);
1218
1219 /* Get the boundary out of a Content-Type: multipart/xyz header field, return
1220 * autorec_alloc()ed copy of it; store su_cs_len() in *len if set */
1221 FL char * mime_param_boundary_get(char const *headerbody, uz *len);
1222
1223 /* Create a autorec_alloc()ed MIME boundary */
1224 FL char * mime_param_boundary_create(void);
1225
1226 /*
1227 * mime-parse.c
1228 */
1229
1230 /* Create MIME part object tree for and of mp */
1231 FL struct mimepart * mime_parse_msg(struct message *mp,
1232 enum mime_parse_flags mpf);
1233
1234 /*
1235 * path.c
1236 */
1237
1238 /* Test to see if the passed file name is a directory, return true if it is.
1239 * If check_access is set, we also access(2): if it is TRUM1 only X_OK|R_OK is
1240 * tested, otherwise X_OK|R_OK|W_OK. */
1241 FL boole n_is_dir(char const *name, boole check_access);
1242
1243 /* Recursively create a directory */
1244 FL boole n_path_mkdir(char const *name);
1245
1246 /* Delete a file, but only if the file is a plain file; return FAL0 on system
1247 * error and TRUM1 if name is not a plain file, return TRU1 on success */
1248 FL boole n_path_rm(char const *name);
1249
1250 /* A get-wd..restore-wd approach */
1251 FL enum okay cwget(struct cw *cw);
1252 FL enum okay cwret(struct cw *cw);
1253 FL void cwrelse(struct cw *cw);
1254
1255 /*
1256 * quit.c
1257 */
1258
1259 /* Save all of the undetermined messages at the top of "mbox". Save all
1260 * untouched messages back in the system mailbox. Remove the system mailbox,
1261 * if none saved there.
1262 * TODO v15 Note: assumes hold_sigs() has been called _and_ can be temporarily
1263 * TODO dropped via a single rele_sigs() if hold_sigs_on */
1264 FL boole quit(boole hold_sigs_on);
1265
1266 /* Adjust the message flags in each message */
1267 FL int holdbits(void);
1268
1269 /* Create another temporary file and copy user's mbox file darin. If there is
1270 * no mbox, copy nothing. If he has specified "append" don't copy his mailbox,
1271 * just copy saveable entries at the end */
1272 FL enum okay makembox(void);
1273
1274 FL void save_mbox_for_possible_quitstuff(void); /* TODO DROP IF U CAN */
1275
1276 FL int savequitflags(void);
1277
1278 FL void restorequitflags(int);
1279
1280 /*
1281 * send.c
1282 */
1283
1284 /* Send message described by the passed pointer to the passed output buffer.
1285 * Return -1 on error. Adjust the status: field if need be. If doitp is
1286 * given, suppress ignored header fields. prefix is a string to prepend to
1287 * each output line. action = data destination
1288 * (SEND_MBOX,_TOFILE,_TODISP,_QUOTE,_DECRYPT). stats[0] is line count,
1289 * stats[1] is character count. stats may be NULL. Note that stats[0] is
1290 * valid for SEND_MBOX only */
1291 FL int sendmp(struct message *mp, FILE *obuf,
1292 struct n_ignore const *doitp,
1293 char const *prefix, enum sendaction action, u64 *stats);
1294
1295 /*
1296 * sendout.c
1297 */
1298
1299 /* Check whether outgoing transport is via SMTP/SUBMISSION etc.
1300 * It handles all the *mta* (v15-compat: +*smtp*) cases.
1301 * Returns TRU1 if yes and URL parsing succeeded, TRUM1 if *mta* is file:// or
1302 * test:// based, and FAL0 on failure.
1303 * TODO It will assign CPROTO_NONE and only set urlp->url_input for file-based
1304 * TODO and test protos, .url_portno is 0 for the former, U16_MAX for latter.
1305 * TODO Should simply leave all that up to URL, is URL_PROTO_FILExy then). */
1306 FL boole mx_sendout_mta_url(struct mx_url *urlp);
1307
1308 /* For main() only: interface between the command line argument list and the
1309 * mail1 routine which does all the dirty work */
1310 FL int n_mail(enum n_mailsend_flags msf, struct mx_name *to,
1311 struct mx_name *cc, struct mx_name *bcc, char const *subject,
1312 struct mx_attachment *attach, char const *quotefile);
1313
1314 /* `mail' and `Mail' commands, respectively */
1315 FL int c_sendmail(void *v);
1316 FL int c_Sendmail(void *v);
1317
1318 /* Mail a message on standard input to the people indicated in the passed
1319 * header, applying all the address massages first. (Internal interface) */
1320 FL enum okay n_mail1(enum n_mailsend_flags flags, struct header *hp,
1321 struct message *quote, char const *quotefile);
1322
1323 /* Create a Date: header field.
1324 * We compare the localtime() and gmtime() results to get the timezone, because
1325 * numeric timezones are easier to read and because $TZ isn't always set.
1326 * Return number of bytes written of -1 */
1327 FL int mkdate(FILE *fo, char const *field);
1328
1329 /* Dump the to, subject, cc header on the passed file buffer.
1330 * nosend_msg tells us not to dig to deep but to instead go for compose mode or
1331 * editing a message (yet we're stupid and cannot do it any better) - if it is
1332 * TRUM1 then we're really in compose mode and will produce some fields for
1333 * easier filling in (see n_run_editor() proto for this hack) */
1334 FL boole n_puthead(boole nosend_msg, struct header *hp, FILE *fo,
1335 enum gfield w, enum sendaction action,
1336 enum conversion convert, char const *contenttype,
1337 char const *charset);
1338
1339 /* Note: hp->h_to must already have undergone address massage(s), it is taken
1340 * as-is; h_cc and h_bcc are asserted to be NIL. urlp must have undergone
1341 * mx_sendout_mta_url() processing */
1342 FL enum okay n_resend_msg(struct message *mp, struct mx_url *urlp,
1343 struct header *hp, boole add_resent);
1344
1345 /* *save* / $DEAD */
1346 FL void savedeadletter(FILE *fp, boole fflush_rewind_first);
1347
1348 /*
1349 * shexp.c
1350 */
1351
1352 /* Evaluate the string given as a new mailbox name. Supported meta characters:
1353 * . % for my system mail box
1354 * . %user for user's system mail box
1355 * . # for previous file
1356 * . & invoker's mbox file
1357 * . +file file in folder directory
1358 * . any shell meta character (except for FEXP_NSHELL).
1359 * a poor man's vis(3), on name before calling this (and showing the user).
1360 * If FEXP_MULTIOK is set we return an array of terminated strings, the (last)
1361 * result string is terminated via \0\0 and n_PS_EXPAND_MULTIRESULT is set.
1362 * Returns the file name as an auto-reclaimed string */
1363 FL char *fexpand(char const *name, BITENUM_IS(u32,fexp_mode) fexpm);
1364
1365 /* Parse the next shell token from input (->s and ->l are adjusted to the
1366 * remains, data is constant beside that; ->s may be NULL if ->l is 0, if ->l
1367 * EQ UZ_MAX su_cs_len(->s) is used) and append the resulting output to store.
1368 * If cookie is not NULL and we're in double-quotes then ${@} will be exploded
1369 * just as known from the sh(1)ell in that case */
1370 FL BITENUM_IS(u32,n_shexp_state) n_shexp_parse_token(
1371 BITENUM_IS(u32,n_shexp_parse_flags) flags, struct n_string *store,
1372 struct str *input, void const **cookie);
1373
1374 /* Quick+dirty simplified : if an error occurs, returns a copy of *cp and set
1375 * *cp to NULL, otherwise advances *cp to over the parsed token */
1376 FL char *n_shexp_parse_token_cp(BITENUM_IS(u32,n_shexp_parse_flags) flags,
1377 char const **cp);
1378
1379 /* Another variant of parse_token_cp(): unquote the argument, ensure the result
1380 * is "alone": after WS/IFS trimming STATE_STOP must be set, returns TRUM1 if
1381 * not, TRU1 if STATE_OUTPUT is set, TRU2 if not, FAL0 on error */
1382 FL boole n_shexp_unquote_one(struct n_string *store, char const *input);
1383
1384 /* Quote input in a way that can, in theory, be fed into parse_token() again.
1385 * ->s may be NULL if ->l is 0, if ->l EQ UZ_MAX su_cs_len(->s) is used.
1386 * If rndtrip is true we try to make the resulting string "portable" (by
1387 * converting Unicode to \u etc.), otherwise we produce something to be
1388 * consumed "now", i.e., to display for the user.
1389 * Resulting output is _appended_ to store.
1390 * TODO Note: last resort, since \u and $ expansions etc. are necessarily
1391 * TODO already expanded and can thus not be reverted, but ALL we have */
1392 FL struct n_string *n_shexp_quote(struct n_string *store,
1393 struct str const *input, boole rndtrip);
1394 FL char *n_shexp_quote_cp(char const *cp, boole rndtrip);
1395
1396 /* Can name be used as a variable name (for the process environment)?
1397 * I.e., this returns false for special parameter names like $# etc. */
1398 FL boole n_shexp_is_valid_varname(char const *name, boole forenviron);
1399
1400 /* `shcodec' */
1401 FL int c_shcodec(void *vp);
1402
1403 /*
1404 * spam.c
1405 */
1406
1407 #ifdef mx_HAVE_SPAM
1408 /* Direct mappings of the various spam* commands */
1409 FL int c_spam_clear(void *v);
1410 FL int c_spam_set(void *v);
1411 FL int c_spam_forget(void *v);
1412 FL int c_spam_ham(void *v);
1413 FL int c_spam_rate(void *v);
1414 FL int c_spam_spam(void *v);
1415 #endif
1416
1417 /*
1418 * strings.c
1419 */
1420
1421 /* Return a pointer to a dynamic copy of the argument */
1422 FL char *savestr(char const *str su_DBG_LOC_ARGS_DECL);
1423 FL char *savestrbuf(char const *sbuf, uz slen su_DBG_LOC_ARGS_DECL);
1424 #ifdef su_HAVE_DBG_LOC_ARGS
1425 # define savestr(CP) savestr(CP su_DBG_LOC_ARGS_INJ)
1426 # define savestrbuf(CBP,CBL) savestrbuf(CBP, CBL su_DBG_LOC_ARGS_INJ)
1427 #endif
1428
1429 /* Concatenate cp2 onto cp1 (if not NULL), separated by sep (if not '\0') */
1430 FL char *savecatsep(char const *cp1, char sep, char const *cp2
1431 su_DBG_LOC_ARGS_DECL);
1432 #ifdef su_HAVE_DBG_LOC_ARGS
1433 # define savecatsep(S1,SEP,S2) savecatsep(S1, SEP, S2 su_DBG_LOC_ARGS_INJ)
1434 #endif
1435
1436 /* Make copy of argument incorporating old one, if set, separated by space */
1437 #define save2str(S,O) savecatsep(O, ' ', S)
1438
1439 /* strcat */
1440 #define savecat(S1,S2) savecatsep(S1, '\0', S2)
1441
1442 /* */
1443 FL struct str * str_concat_csvl(struct str *self, ...);
1444
1445 /* */
1446 FL struct str *str_concat_cpa(struct str *self, char const * const *cpa,
1447 char const *sep_o_null su_DBG_LOC_ARGS_DECL);
1448 #ifdef su_HAVE_DBG_LOC_ARGS
1449 # define str_concat_cpa(S,A,N) str_concat_cpa(S, A, N su_DBG_LOC_ARGS_INJ)
1450 #endif
1451
1452 /* Plain char* support, not auto-reclaimed (unless noted) */
1453
1454 /* Could the string contain a regular expression?
1455 * NOTE: on change: manual contains several occurrences of this string! */
1456 #define n_is_maybe_regex(S) n_is_maybe_regex_buf(S, su_UZ_MAX)
1457 FL boole n_is_maybe_regex_buf(char const *buf, uz len);
1458
1459 /* Convert a string to lowercase, in-place and with multibyte-aware */
1460 FL void makelow(char *cp);
1461
1462 /* Is *sub* a substring of *str*, case-insensitive and multibyte-aware? */
1463 FL boole substr(char const *str, char const *sub);
1464
1465 /* struct str related support funs TODO _cp->_cs! */
1466
1467 /* *self->s* is n_realloc()ed */
1468 #define n_str_dup(S, T) n_str_assign_buf((S), (T)->s, (T)->l)
1469
1470 /* *self->s* is n_realloc()ed; if buflen==UZ_MAX su_cs_len() is called unless
1471 * buf is NULL; buf may be NULL if buflen is 0 */
1472 FL struct str *n_str_assign_buf(struct str *self, char const *buf, uz buflen
1473 su_DBG_LOC_ARGS_DECL);
1474 #define n_str_assign(S, T) n_str_assign_buf(S, (T)->s, (T)->l)
1475 #define n_str_assign_cp(S, CP) n_str_assign_buf(S, CP, UZ_MAX)
1476
1477 /* *self->s* is n_realloc()ed, *self->l* incremented; if buflen==UZ_MAX
1478 * su_cs_len() is called unless buf is NULL; buf may be NULL if buflen is 0 */
1479 FL struct str *n_str_add_buf(struct str *self, char const *buf, uz buflen
1480 su_DBG_LOC_ARGS_DECL);
1481 #define n_str_add(S, T) n_str_add_buf(S, (T)->s, (T)->l)
1482 #define n_str_add_cp(S, CP) n_str_add_buf(S, CP, UZ_MAX)
1483
1484 #ifdef su_HAVE_DBG_LOC_ARGS
1485 # define n_str_assign_buf(S,B,BL) \
1486 n_str_assign_buf(S, B, BL su_DBG_LOC_ARGS_INJ)
1487 # define n_str_add_buf(S,B,BL) n_str_add_buf(S, B, BL su_DBG_LOC_ARGS_INJ)
1488 #endif
1489
1490 /* Remove leading and trailing su_cs_is_space()s and *ifs-ws*, respectively.
1491 * The ->s and ->l of the string will be adjusted, but no NUL termination will
1492 * be applied to a possibly adjusted buffer!
1493 * If dofaults is set, " \t\n" is always trimmed (in addition).
1494 * Note trimming does not copy, it only adjusts the pointer/length */
1495 FL struct str *n_str_trim(struct str *self, enum n_str_trim_flags stf);
1496 FL struct str *n_str_trim_ifs(struct str *self, boole dodefaults);
1497
1498 /* struct n_string
1499 * May have NIL buffer, may contain embedded NULs */
1500
1501 FL struct n_string *n__string_clear(struct n_string *self);
1502
1503 /* Lifetime. n_string_gut() is optional for _creat_auto() strings */
1504 INLINE struct n_string *
n_string_creat(struct n_string * self)1505 n_string_creat(struct n_string *self){
1506 self->s_dat = NIL;
1507 self->s_len = self->s_auto = self->s_size = 0;
1508 return self;
1509 }
1510
1511 INLINE struct n_string *
n_string_creat_auto(struct n_string * self)1512 n_string_creat_auto(struct n_string *self){
1513 self->s_dat = NIL;
1514 self->s_len = self->s_auto = self->s_size = 0;
1515 self->s_auto = TRU1;
1516 return self;
1517 }
1518
n_string_gut(struct n_string * self)1519 INLINE void n_string_gut(struct n_string *self){
1520 if(self->s_dat != NIL)
1521 n__string_clear(self);
1522 }
1523
1524 INLINE struct n_string *
n_string_trunc(struct n_string * self,uz len)1525 n_string_trunc(struct n_string *self, uz len){
1526 ASSERT(UCMP(z, len, <=, self->s_len));
1527 self->s_len = S(u32,len);
1528 return self;
1529 }
1530
1531 INLINE struct n_string *
n_string_take_ownership(struct n_string * self,char * buf,u32 size,u32 len)1532 n_string_take_ownership(struct n_string *self, char *buf, u32 size, u32 len){
1533 ASSERT(self->s_dat == NIL);
1534 ASSERT(size == 0 || buf != NIL);
1535 ASSERT(len == 0 || len < size);
1536 self->s_dat = buf;
1537 self->s_size = size;
1538 self->s_len = len;
1539 return self;
1540 }
1541
1542 INLINE struct n_string *
n_string_drop_ownership(struct n_string * self)1543 n_string_drop_ownership(struct n_string *self){
1544 self->s_dat = NIL;
1545 self->s_len = self->s_size = 0;
1546 return self;
1547 }
1548
1549 INLINE struct n_string *
n_string_clear(struct n_string * self)1550 n_string_clear(struct n_string *self){
1551 if(self->s_size > 0)
1552 self = n__string_clear(self);
1553 return self;
1554 }
1555
1556 /* Check whether a buffer of Len bytes can be inserted into S(elf) */
n_string_get_can_book(uz len)1557 INLINE boole n_string_get_can_book(uz len){
1558 return (S(uz,S32_MAX) - Z_ALIGN(1) > len);
1559 }
1560
n_string_can_book(struct n_string * self,uz len)1561 INLINE boole n_string_can_book(struct n_string *self, uz len){
1562 return (n_string_get_can_book(len) &&
1563 S(uz,S32_MAX) - Z_ALIGN(1) - len > self->s_len);
1564 }
1565
1566 /* Reserve room for noof additional bytes, but don't adjust length (yet) */
1567 FL struct n_string *n_string_reserve(struct n_string *self, uz noof
1568 su_DBG_LOC_ARGS_DECL);
1569 #define n_string_book n_string_reserve
1570
1571 /* Resize to exactly nlen bytes; any new storage isn't initialized */
1572 FL struct n_string *n_string_resize(struct n_string *self, uz nlen
1573 su_DBG_LOC_ARGS_DECL);
1574
1575 #ifdef su_HAVE_DBG_LOC_ARGS
1576 # define n_string_reserve(S,N) (n_string_reserve)(S, N su_DBG_LOC_ARGS_INJ)
1577 # define n_string_resize(S,N) (n_string_resize)(S, N su_DBG_LOC_ARGS_INJ)
1578 #endif
1579
1580 /* */
1581 FL struct n_string *n_string_push_buf(struct n_string *self, char const *buf,
1582 uz buflen su_DBG_LOC_ARGS_DECL);
1583 #define n_string_push(S, T) n_string_push_buf(S, (T)->s_len, (T)->s_dat)
1584 #define n_string_push_cp(S,CP) n_string_push_buf(S, CP, UZ_MAX)
1585 FL struct n_string *n_string_push_c(struct n_string *self, char c
1586 su_DBG_LOC_ARGS_DECL);
1587
1588 #define n_string_assign(S,T) ((S)->s_len = 0, n_string_push(S, T))
1589 #define n_string_assign_c(S,C) ((S)->s_len = 0, n_string_push_c(S, C))
1590 #define n_string_assign_cp(S,CP) ((S)->s_len = 0, n_string_push_cp(S, CP))
1591 #define n_string_assign_buf(S,B,BL) \
1592 ((S)->s_len = 0, n_string_push_buf(S, B, BL))
1593
1594 #ifdef su_HAVE_DBG_LOC_ARGS
1595 # define n_string_push_buf(S,B,BL) \
1596 (n_string_push_buf)(S, B, BL su_DBG_LOC_ARGS_INJ)
1597 # define n_string_push_c(S,C) (n_string_push_c)(S, C su_DBG_LOC_ARGS_INJ)
1598 #endif
1599
1600 /* */
1601 FL struct n_string *n_string_unshift_buf(struct n_string *self,
1602 char const *buf, uz buflen su_DBG_LOC_ARGS_DECL);
1603 #define n_string_unshift(S,T) \
1604 n_string_unshift_buf(S, (T)->s_len, (T)->s_dat)
1605 #define n_string_unshift_cp(S,CP) \
1606 n_string_unshift_buf(S, CP, UZ_MAX)
1607 FL struct n_string *n_string_unshift_c(struct n_string *self, char c
1608 su_DBG_LOC_ARGS_DECL);
1609
1610 #ifdef su_HAVE_DBG_LOC_ARGS
1611 # define n_string_unshift_buf(S,B,BL) \
1612 (n_string_unshift_buf)(S, B, BL su_DBG_LOC_ARGS_INJ)
1613 # define n_string_unshift_c(S,C) \
1614 (n_string_unshift_c)(S, C su_DBG_LOC_ARGS_INJ)
1615 #endif
1616
1617 /* */
1618 FL struct n_string *n_string_insert_buf(struct n_string *self, uz idx,
1619 char const *buf, uz buflen su_DBG_LOC_ARGS_DECL);
1620 #define n_string_insert(S,I,T) \
1621 n_string_insert_buf(S, I, (T)->s_len, (T)->s_dat)
1622 #define n_string_insert_cp(S,I,CP) \
1623 n_string_insert_buf(S, I, CP, UZ_MAX)
1624 FL struct n_string *n_string_insert_c(struct n_string *self, uz idx,
1625 char c su_DBG_LOC_ARGS_DECL);
1626
1627 #ifdef su_HAVE_DBG_LOC_ARGS
1628 # define n_string_insert_buf(S,I,B,BL) \
1629 (n_string_insert_buf)(S, I, B, BL su_DBG_LOC_ARGS_INJ)
1630 # define n_string_insert_c(S,I,C) \
1631 (n_string_insert_c)(S, I, C su_DBG_LOC_ARGS_INJ)
1632 #endif
1633
1634 /* */
1635 FL struct n_string *n_string_cut(struct n_string *self, uz idx,
1636 uz len);
1637
1638 /* Ensure self has a - NUL terminated - buffer, and return that.
1639 * The latter may return the pointer to an internal empty RODATA instead */
1640 FL char *n_string_cp(struct n_string *self su_DBG_LOC_ARGS_DECL);
1641 FL char const *n_string_cp_const(struct n_string const *self);
1642
1643 #ifdef su_HAVE_DBG_LOC_ARGS
1644 # define n_string_cp(S) (n_string_cp)(S su_DBG_LOC_ARGS_INJ)
1645 #endif
1646
1647 /*
1648 * thread.c
1649 */
1650
1651 /* */
1652 FL int c_thread(void *vp);
1653
1654 /* */
1655 FL int c_unthread(void *vp);
1656
1657 /* */
1658 FL struct message * next_in_thread(struct message *mp);
1659 FL struct message * prev_in_thread(struct message *mp);
1660 FL struct message * this_in_thread(struct message *mp, long n);
1661
1662 /* Sorted mode is internally just a variant of threaded mode with all m_parent
1663 * and m_child links being NULL */
1664 FL int c_sort(void *vp);
1665
1666 /* */
1667 FL int c_collapse(void *v);
1668 FL int c_uncollapse(void *v);
1669
1670 /* */
1671 FL void uncollapse1(struct message *mp, int always);
1672
1673 /*
1674 * tls.c
1675 */
1676
1677 #ifdef mx_HAVE_TLS
1678 /* */
1679 FL void n_tls_set_verify_level(struct mx_url const *urlp);
1680
1681 /* */
1682 FL boole n_tls_verify_decide(void);
1683
1684 /* */
1685 FL boole mx_smime_split(FILE *ip, FILE **hp, FILE **bp, long xcount,
1686 boole keep);
1687
1688 /* */
1689 FL FILE * smime_sign_assemble(FILE *hp, FILE *bp, FILE *sp,
1690 char const *message_digest);
1691
1692 /* */
1693 FL FILE * smime_encrypt_assemble(FILE *hp, FILE *yp);
1694
1695 /* hp and bp are NOT closed */
1696 FL struct message *mx_smime_decrypt_assemble(struct message *mp, FILE *hp,
1697 FILE *bp);
1698
1699 /* `certsave' */
1700 FL int c_certsave(void *vp);
1701
1702 /* */
1703 FL boole n_tls_rfc2595_hostname_match(char const *host, char const *pattern);
1704
1705 /* `tls' */
1706 FL int c_tls(void *vp);
1707 #endif /* mx_HAVE_TLS */
1708
1709 /*
1710 * xtls.c
1711 */
1712
1713 #ifdef mx_HAVE_XTLS
1714 /* Our wrapper for RAND_bytes(3); the implementation exists only when
1715 * HAVE_RANDOM is RANDOM_IMPL_TLS, though */
1716 FL void mx_tls_rand_bytes(void *buf, uz blen);
1717
1718 /* Will fill in a non-NULL *urlp->url_cert_fprint with auto-reclaimed
1719 * buffer on success, otherwise urlp is constant */
1720 FL boole n_tls_open(struct mx_url *urlp, struct mx_socket *sp);
1721
1722 /* */
1723 FL void ssl_gen_err(char const *fmt, ...);
1724
1725 /* */
1726 FL int c_verify(void *vp);
1727
1728 /* */
1729 FL FILE * smime_sign(FILE *ip, char const *addr);
1730
1731 /* */
1732 FL FILE * smime_encrypt(FILE *ip, char const *certfile, char const *to);
1733
1734 FL struct message * smime_decrypt(struct message *m, char const *to,
1735 char const *cc, boole is_a_verify_call);
1736
1737 /* */
1738 FL enum okay smime_certsave(struct message *m, int n, FILE *op);
1739
1740 #endif /* mx_HAVE_XTLS */
1741
1742 /*
1743 * obs-imap.c
1744 */
1745
1746 #ifdef mx_HAVE_IMAP
1747 FL void n_go_onintr_for_imap(void);
1748
1749 /* The former returns the input again if no conversion is necessary */
1750 FL char const *imap_path_encode(char const *path, boole *err_or_null);
1751 FL char *imap_path_decode(char const *path, boole *err_or_null);
1752
1753 FL char const * imap_fileof(char const *xcp);
1754 FL enum okay imap_noop(void);
1755 FL enum okay imap_select(struct mailbox *mp, off_t *size, int *count,
1756 const char *mbx, enum fedit_mode fm);
1757 FL int imap_setfile(char const *who, const char *xserver, enum fedit_mode fm);
1758 FL enum okay imap_header(struct message *m);
1759 FL enum okay imap_body(struct message *m);
1760 FL void imap_getheaders(int bot, int top);
1761 FL boole imap_quit(boole hold_sigs_on);
1762 FL enum okay imap_undelete(struct message *m, int n);
1763 FL enum okay imap_unread(struct message *m, int n);
1764 FL int c_imapcodec(void *vp);
1765 FL int c_imap_imap(void *vp);
1766 FL int imap_newmail(int nmail);
1767 FL enum okay imap_append(const char *xserver, FILE *fp, long offset);
1768 FL int imap_folders(const char *name, int strip);
1769 FL enum okay imap_copy(struct message *m, int n, const char *name);
1770 # ifdef mx_HAVE_IMAP_SEARCH
1771 FL sz imap_search1(const char *spec, int f);
1772 # endif
1773 FL int imap_thisaccount(const char *cp);
1774 FL enum okay imap_remove(const char *name);
1775 FL enum okay imap_rename(const char *old, const char *new);
1776 FL enum okay imap_dequeue(struct mailbox *mp, FILE *fp);
1777 FL int c_connect(void *vp);
1778 FL int c_disconnect(void *vp);
1779 FL int c_cache(void *vp);
1780 FL int disconnected(const char *file);
1781 FL void transflags(struct message *omessage, long omsgCount,
1782 int transparent);
1783 FL time_t imap_read_date_time(const char *cp);
1784 FL const char * imap_make_date_time(time_t t);
1785
1786 /* Extract the protocol base and return a duplicate */
1787 FL char *protbase(char const *cp su_DBG_LOC_ARGS_DECL);
1788 # ifdef su_HAVE_DBG_LOC_ARGS
1789 # define protbase(CP) (protbase)(CP su_DBG_LOC_ARGS_INJ)
1790 # endif
1791 #endif /* mx_HAVE_IMAP */
1792
1793 /*
1794 * obs-imap-cache.c
1795 */
1796
1797 #ifdef mx_HAVE_IMAP
1798 FL enum okay getcache1(struct mailbox *mp, struct message *m,
1799 enum needspec need, int setflags);
1800 FL enum okay getcache(struct mailbox *mp, struct message *m,
1801 enum needspec need);
1802 FL void putcache(struct mailbox *mp, struct message *m);
1803 FL void initcache(struct mailbox *mp);
1804 FL void purgecache(struct mailbox *mp, struct message *m, long mc);
1805 FL void delcache(struct mailbox *mp, struct message *m);
1806 FL enum okay cache_setptr(enum fedit_mode fm, int transparent);
1807 FL enum okay cache_list(struct mailbox *mp, char const *base, int strip,
1808 FILE *fp);
1809 FL enum okay cache_remove(char const *name);
1810 FL enum okay cache_rename(char const *old, char const *new);
1811 FL u64 cached_uidvalidity(struct mailbox *mp);
1812 FL FILE * cache_queue(struct mailbox *mp);
1813 FL enum okay cache_dequeue(struct mailbox *mp);
1814 #endif /* mx_HAVE_IMAP */
1815
1816 /*
1817 * obs-lzw.c
1818 */
1819 #ifdef mx_HAVE_IMAP
1820 FL int zwrite(void *cookie, const char *wbp, int num);
1821 FL int zfree(void *cookie);
1822 FL int zread(void *cookie, char *rbp, int num);
1823 FL void * zalloc(FILE *fp);
1824 #endif /* mx_HAVE_IMAP */
1825
1826 #ifndef mx_HAVE_AMALGAMATION
1827 # undef FL
1828 # define FL
1829 #endif
1830
1831 /* s-it-mode */
1832