2 * S-nail - a mail user agent derived from Berkeley Mail.
4 * Copyright (c) 2000-2004 Gunnar Ritter, Freiburg i. Br., Germany.
5 * Copyright (c) 2012 Steffen "Daode" Nurpmeso.
9 * Copyright (c) 1992, 1993
10 * The Regents of the University of California. All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the University of
23 * California, Berkeley and its contributors.
24 * 4. Neither the name of the University nor the names of its contributors
25 * may be used to endorse or promote products derived from this software
26 * without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 void panic(const char *format
, ...);
45 void touch(struct message
*mp
);
46 int is_dir(char *name
);
47 int argcount(char **argv
);
48 void i_strcpy(char *dest
, const char *src
, int size
);
49 char *i_strdup(const char *src
);
50 void makelow(char *cp
);
51 int substr(const char *str
, const char *sub
);
52 char *colalign(const char *cp
, int col
, int fill
);
53 void try_pager(FILE *fp
);
56 void alter(char *name
);
57 int blankline(char *linebuf
);
58 int anyof(char const *s1
, char const *s2
);
59 int is_prefix(const char *as1
, const char *as2
);
60 char *last_at_before_slash(const char *sp
);
61 enum protocol
which_protocol(const char *name
);
62 const char *protfile(const char *xcp
);
63 char *protbase(const char *cp
);
64 int disconnected(const char *file
);
65 unsigned pjw(const char *cp
);
66 long nextprime(long n
);
67 char *strenc(const char *cp
);
68 char *strdec(const char *cp
);
70 char *md5tohex(const void *vp
);
71 char *cram_md5_string(const char *user
, const char *pass
, const char *b64
);
74 char *getpassword(struct termios
*otio
, int *reset_tio
, const char *query
);
75 void transflags(struct message
*omessage
, long omsgCount
, int transparent
);
76 char *getrandstring(size_t length
);
77 void out_of_memory(void);
78 void *smalloc(size_t s
);
79 void *srealloc(void *v
, size_t s
);
80 void *scalloc(size_t nmemb
, size_t size
);
81 char *sstpcpy(char *dst
, const char *src
);
82 char *sstrdup(const char *cp
);
83 enum okay
makedir(const char *name
);
84 enum okay
cwget(struct cw
*cw
);
85 enum okay
cwret(struct cw
*cw
);
86 void cwrelse(struct cw
*cw
);
87 void makeprint(struct str
*in
, struct str
*out
);
88 char *prstr(const char *s
);
89 int prout(const char *s
, size_t sz
, FILE *fp
);
90 int putuc(int u
, int c
, FILE *fp
);
91 int asccasecmp(const char *s1
, const char *s2
);
92 int ascncasecmp(const char *s1
, const char *s2
, size_t sz
);
93 char *asccasestr(const char *haystack
, const char *xneedle
);
96 char *strtob64(const char *p
);
97 char *memtob64(const void *vp
, size_t isz
);
98 size_t mime_write_tob64(struct str
*in
, FILE *fo
, int is_header
);
99 void mime_fromb64(struct str
*in
, struct str
*out
, int is_text
);
100 void mime_fromb64_b(struct str
*in
, struct str
*out
, int is_text
, FILE *f
);
103 enum okay
getcache1(struct mailbox
*mp
, struct message
*m
,
104 enum needspec need
, int setflags
);
105 enum okay
getcache(struct mailbox
*mp
, struct message
*m
, enum needspec need
);
106 void putcache(struct mailbox
*mp
, struct message
*m
);
107 void initcache(struct mailbox
*mp
);
108 void purgecache(struct mailbox
*mp
, struct message
*m
, long mc
);
109 void delcache(struct mailbox
*mp
, struct message
*m
);
110 enum okay
cache_setptr(int transparent
);
111 enum okay
cache_list(struct mailbox
*mp
, const char *base
, int strip
, FILE *fp
);
112 enum okay
cache_remove(const char *name
);
113 enum okay
cache_rename(const char *old
, const char *new);
114 unsigned long cached_uidvalidity(struct mailbox
*mp
);
115 FILE *cache_queue(struct mailbox
*mp
);
116 enum okay
cache_dequeue(struct mailbox
*mp
);
119 char *get_pager(void);
120 int headers(void *v
);
123 int screensize(void);
125 void printhead(int mesg
, FILE *f
, int threaded
);
127 int pcmdlist(void *v
);
128 char *laststring(char *linebuf
, int *flag
, int strip
);
134 int pipecmd(void *v
);
135 int Pipecmd(void *v
);
139 int folders(void *v
);
145 int copycmd(void *v
);
146 int Copycmd(void *v
);
149 int cdecrypt(void *v
);
150 int cDecrypt(void *v
);
151 int clobber(void *v
);
155 int deltype(void *v
);
156 int undeletecmd(void *v
);
157 int retfield(void *v
);
158 int igfield(void *v
);
159 int saveretfield(void *v
);
160 int saveigfield(void *v
);
161 int fwdretfield(void *v
);
162 int fwdigfield(void *v
);
163 int unignore(void *v
);
164 int unretain(void *v
);
165 int unsaveignore(void *v
);
166 int unsaveretain(void *v
);
167 int unfwdignore(void *v
);
168 int unfwdretain(void *v
);
175 int respond(void *v
);
176 int respondall(void *v
);
177 int respondsender(void *v
);
178 int followup(void *v
);
179 int followupall(void *v
);
180 int followupsender(void *v
);
181 int preserve(void *v
);
184 int messize(void *v
);
189 int ungroup(void *v
);
192 int Respond(void *v
);
193 int Followup(void *v
);
194 int forwardcmd(void *v
);
195 int Forwardcmd(void *v
);
197 int elsecmd(void *v
);
198 int endifcmd(void *v
);
199 int alternates(void *v
);
200 int resendcmd(void *v
);
201 int Resendcmd(void *v
);
202 int newmail(void *v
);
203 int shortcut(void *v
);
204 struct shortcut
*get_shortcut(const char *str
);
205 int unshortcut(void *v
);
206 struct oldaccount
*get_oldaccount(const char *name
);
207 int account(void *v
);
209 int cunflag(void *v
);
210 int canswered(void *v
);
211 int cunanswered(void *v
);
213 int cundraft(void *v
);
215 int cunkill(void *v
);
218 int cremove(void *v
);
219 int crename(void *v
);
224 struct attachment
*edit_attachments(struct attachment
*attach
);
225 struct attachment
*add_attachment(struct attachment
*attach
, char *file
,
227 FILE *collect(struct header
*hp
, int printheaders
, struct message
*mp
,
228 char *quotefile
, int doprefix
, int tflag
);
229 void savedeadletter(FILE *fp
);
232 int fcntl_lock(int fd
, int type
);
233 int dot_lock(const char *fname
, int fd
, int pollinterval
, FILE *fp
,
235 void dot_unlock(const char *fname
);
240 FILE *run_editor(FILE *fp
, off_t size
, int type
, int readonly
,
241 struct header
*hp
, struct message
*mp
, enum sendaction action
,
242 sighandler_type oldint
);
245 void setptr(FILE *ibuf
, off_t offset
);
246 int putline(FILE *obuf
, char *linebuf
, size_t count
);
247 #define readline(a, b, c) readline_restart(a, b, c, 0)
248 int readline_restart(FILE *ibuf
, char **linebuf
, size_t *linesize
, size_t n
);
249 FILE *setinput(struct mailbox
*mp
, struct message
*m
, enum needspec need
);
250 struct message
*setdot(struct message
*mp
);
253 void relsesigs(void);
254 off_t
fsize(FILE *iob
);
255 char *file_expand(char const *name
);
256 char *expand(char *name
);
257 int getfold(char *name
, int size
);
258 char *getdeadletter(void);
259 char *fgetline(char **line
, size_t *linesize
, size_t *count
,
260 size_t *llen
, FILE *fp
, int appendnl
);
261 void newline_appended(void);
262 enum okay
get_body(struct message
*mp
);
263 int sclose(struct sock
*sp
);
264 enum okay
swrite(struct sock
*sp
, const char *data
);
265 enum okay
swrite1(struct sock
*sp
, const char *data
, int sz
, int use_buffer
);
266 int sgetline(char **line
, size_t *linesize
, size_t *linelen
, struct sock
*sp
);
267 enum okay
sopen(const char *xserver
, struct sock
*sp
, int use_ssl
,
268 const char *uhp
, const char *portstr
, int verbose
);
271 char *getname(int uid
);
272 int getuserid(char *name
);
276 int getopt(int argc
, char *const argv
[], const char *optstring
);
280 int is_head(char *linebuf
, size_t linelen
);
281 void parse(char *line
, size_t linelen
, struct headline
*hl
, char *pbuf
);
282 void extract_header(FILE *fp
, struct header
*hp
);
283 #define hfieldX(a, b) hfield_mult(a, b, 1)
284 #define hfield1(a, b) hfield_mult(a, b, 0)
285 char *hfield_mult(char *field
, struct message
*mp
, int mult
);
286 char *thisfield(const char *linebuf
, const char *field
);
287 char *nameof(struct message
*mp
, int reptype
);
288 char const *skip_comment(char const *cp
);
289 char *routeaddr(const char *name
);
290 #define is_fileorpipe_addr(NP) \
291 (((NP)->n_flags & NAME_ADDRSPEC_ISFILEORPIPE) != 0)
292 int is_addr_invalid(struct name
*np
, int putmsg
);
293 char *skinned_name(struct name
*np
);
294 char *skin(char *name
);
295 int addrspec_with_guts(int doskin
, char const *name
, struct addrguts
*agp
);
296 char *realname(char *name
);
297 char *name1(struct message
*mp
, int reptype
);
298 int msgidcmp(const char *s1
, const char *s2
);
299 int is_ign(char *field
, size_t fieldlen
, struct ignoretab ignore
[2]);
300 int member(char *realfield
, struct ignoretab
*table
);
301 char *fakefrom(struct message
*mp
);
302 char *fakedate(time_t t
);
303 char const *nexttoken(char const *cp
);
304 time_t unixtime(char const *from
);
305 time_t rfctime(char const *date
);
306 time_t combinetime(int year
, int month
, int day
,
307 int hour
, int minute
, int second
);
308 void substdate(struct message
*m
);
309 int check_from_and_sender(struct name
*fromfield
, struct name
*senderfield
);
310 char *getsender(struct message
*m
);
313 enum okay
imap_noop(void);
314 enum okay
imap_select(struct mailbox
*mp
, off_t
*size
, int *count
,
316 int imap_setfile(const char *xserver
, int newmail
, int isedit
);
317 enum okay
imap_header(struct message
*m
);
318 enum okay
imap_body(struct message
*m
);
319 void imap_getheaders(int bot
, int top
);
320 void imap_quit(void);
321 enum okay
imap_undelete(struct message
*m
, int n
);
322 enum okay
imap_unread(struct message
*m
, int n
);
323 int imap_imap(void *vp
);
324 int imap_newmail(int autoinc
);
325 enum okay
imap_append(const char *xserver
, FILE *fp
);
326 void imap_folders(const char *name
, int strip
);
327 enum okay
imap_copy(struct message
*m
, int n
, const char *name
);
328 enum okay
imap_search1(const char *spec
, int f
);
329 int imap_thisaccount(const char *cp
);
330 enum okay
imap_remove(const char *name
);
331 enum okay
imap_rename(const char *old
, const char *new);
332 enum okay
imap_dequeue(struct mailbox
*mp
, FILE *fp
);
333 int cconnect(void *vp
);
334 int cdisconnect(void *vp
);
335 int ccache(void *vp
);
336 time_t imap_read_date_time(const char *cp
);
337 time_t imap_read_date(const char *cp
);
338 const char *imap_make_date_time(time_t t
);
339 char *imap_quotestr(const char *s
);
340 char *imap_unquotestr(const char *s
);
345 enum okay
imap_search(const char *spec
, int f
);
349 int cungood(void *v
);
350 int cunjunk(void *v
);
351 int cclassify(void *v
);
352 int cprobability(void *v
);
355 int setfile(char *name
, int newmail
);
356 int newmailinfo(int omsgCount
);
358 int execute(char *linebuf
, int contxt
, size_t linesize
);
359 void setmsize(int sz
);
361 void announce(int printheaders
);
362 int newfileinfo(void);
363 int getmdot(int newmail
);
364 int pversion(void *v
);
365 void load(char *name
);
366 void initbox(const char *name
);
369 int getmsglist(char *buf
, int *vector
, int flags
);
370 int getrawlist(const char *line
, size_t linesize
,
371 char **argv
, int argc
, int echolist
);
372 int first(int f
, int m
);
373 void mark(int mesg
, int f
);
376 int zwrite(void *cookie
, const char *wbp
, int num
);
377 int zfree(void *cookie
);
378 int zread(void *cookie
, char *rbp
, int num
);
379 void *zalloc(FILE *fp
);
382 int cdefine(void *v
);
383 int define1(const char *name
, int account
);
386 int callaccount(const char *name
);
387 int callhook(const char *name
, int newmail
);
388 int listaccounts(FILE *fp
);
389 int cdefines(void *v
);
390 void delaccount(const char *name
);
393 int maildir_setfile(const char *name
, int newmail
, int isedit
);
394 void maildir_quit(void);
395 enum okay
maildir_append(const char *name
, FILE *fp
);
396 enum okay
maildir_remove(const char *name
);
399 int main(int argc
, char *argv
[]);
402 char *gettcharset(void);
403 char *need_hdrconv(struct header
*hp
, enum gfield w
);
405 iconv_t
iconv_open_ft(const char *tocode
, const char *fromcode
);
406 size_t iconv_ft(iconv_t cd
, char **inb
, size_t *inbleft
,
407 char **outb
, size_t *outbleft
, int tolerant
);
409 enum mimeenc
mime_getenc(char *h
);
410 int mime_getcontent(char *h
);
411 char *mime_getparam(char *param
, char *h
);
412 char *mime_getboundary(char *h
);
413 char *mime_filecontent(char *name
);
414 int get_mime_convert(FILE *fp
, char **contenttype
, char **charset
,
415 enum mimeclean
*isclean
, int dosign
);
416 void mime_fromhdr(struct str
*in
, struct str
*out
, enum tdflags flags
);
417 char *mime_fromaddr(char *name
);
418 size_t prefixwrite(void *ptr
, size_t size
, size_t nmemb
, FILE *f
,
419 char *prefix
, size_t prefixlen
);
420 size_t mime_write(void *ptr
, size_t size
, FILE *f
,
421 enum conversion convert
, enum tdflags dflags
,
422 char *prefix
, size_t prefixlen
, char **rest
, size_t *restsize
);
425 struct name
*nalloc(char *str
, enum gfield ntype
);
426 struct name
*ndup(struct name
*np
, enum gfield ntype
);
427 struct name
*extract(char *line
, enum gfield ntype
);
428 struct name
*sextract(char *line
, enum gfield ntype
);
429 struct name
*lextract(char *line
, enum gfield ntype
);
430 char *detract(struct name
*np
, enum gfield ntype
);
431 struct name
*checkaddrs(struct name
*np
);
432 struct name
*outof(struct name
*names
, FILE *fo
, struct header
*hp
);
433 struct name
*usermap(struct name
*names
);
434 struct name
*cat(struct name
*n1
, struct name
*n2
);
435 char **unpack(struct name
*np
);
436 struct name
*elide(struct name
*names
);
437 int count(struct name
*np
);
438 struct name
*delete_alternates(struct name
*np
);
439 int is_myname(char *name
);
443 enum okay
ssl_open(const char *server
, struct sock
*sp
, const char *uhp
);
444 void nss_gen_err(const char *fmt
, ...);
449 enum okay
ssl_open(const char *server
, struct sock
*sp
, const char *uhp
);
450 void ssl_gen_err(const char *fmt
, ...);
452 int cverify(void *vp
);
453 FILE *smime_sign(FILE *ip
, struct header
*);
454 FILE *smime_encrypt(FILE *ip
, const char *certfile
, const char *to
);
455 struct message
*smime_decrypt(struct message
*m
, const char *to
,
456 const char *cc
, int signcall
);
457 enum okay
smime_certsave(struct message
*m
, int n
, FILE *op
);
460 enum okay
pop3_noop(void);
461 int pop3_setfile(const char *server
, int newmail
, int isedit
);
462 enum okay
pop3_header(struct message
*m
);
463 enum okay
pop3_body(struct message
*m
);
464 void pop3_quit(void);
467 sighandler_type
safe_signal(int signum
, sighandler_type handler
);
468 FILE *safe_fopen(const char *file
, const char *mode
, int *omode
);
469 FILE *Fopen(const char *file
, const char *mode
);
470 FILE *Fdopen(int fd
, const char *mode
);
471 int Fclose(FILE *fp
);
472 FILE *Zopen(const char *file
, const char *mode
, int *compression
);
473 FILE *Popen(const char *cmd
, const char *mode
, const char *shell
, int newfd1
);
474 int Pclose(FILE *ptr
);
475 void close_all_files(void);
476 int run_command(char *cmd
, sigset_t
*mask
, int infd
, int outfd
,
477 char *a0
, char *a1
, char *a2
);
478 int start_command(const char *cmd
, sigset_t
*mask
, int infd
, int outfd
,
479 const char *a0
, const char *a1
, const char *a2
);
480 void prepare_child(sigset_t
*nset
, int infd
, int outfd
);
481 void sigchild(int signo
);
482 void free_child(int pid
);
483 int wait_child(int pid
);
486 int quitcmd(void *v
);
489 enum okay
makembox(void);
490 int savequitflags(void);
491 void restorequitflags(int);
494 char *foldergets(char **s
, size_t *size
, size_t *count
, size_t *llen
,
497 #define send(a, b, c, d, e, f) xsend(a, b, c, d, e, f)
498 int send(struct message
*mp
, FILE *obuf
, struct ignoretab
*doign
,
499 char *prefix
, enum sendaction action
, off_t
*stats
);
502 char *makeboundary(void);
503 int mail(struct name
*to
, struct name
*cc
, struct name
*bcc
,
504 struct name
*smopts
, char *subject
, struct attachment
*attach
,
505 char *quotefile
, int recipient_record
, int tflag
, int Eflag
);
506 int sendmail(void *v
);
507 int Sendmail(void *v
);
508 enum okay
mail1(struct header
*hp
, int printheaders
, struct message
*quote
,
509 char *quotefile
, int recipient_record
, int doprefix
, int tflag
,
511 int mkdate(FILE *fo
, const char *field
);
512 int puthead(struct header
*hp
, FILE *fo
, enum gfield w
,
513 enum sendaction action
, enum conversion convert
,
514 char *contenttype
, char *charset
);
515 enum okay
resend_msg(struct message
*mp
, struct name
*to
, int add_resent
);
518 char *nodename(int mayoverride
);
519 char *myaddrs(struct header
*hp
);
520 char *myorigin(struct header
*hp
);
521 char *smtp_auth_var(const char *type
, const char *addr
);
522 int smtp_mta(char *server
, struct name
*to
, FILE *fi
, struct header
*hp
,
523 const char *user
, const char *password
, const char *skinned
);
526 void ssl_set_vrfy_level(const char *uhp
);
527 enum okay
ssl_vrfy_decide(void);
528 char *ssl_method_string(const char *uhp
);
529 enum okay
smime_split(FILE *ip
, FILE **hp
, FILE **bp
, long xcount
, int keep
);
530 FILE *smime_sign_assemble(FILE *hp
, FILE *bp
, FILE *sp
);
531 FILE *smime_encrypt_assemble(FILE *hp
, FILE *yp
);
532 struct message
*smime_decrypt_assemble(struct message
*m
, FILE *hp
, FILE *bp
);
533 int ccertsave(void *v
);
534 enum okay
rfc2595_hostname_match(const char *host
, const char *pattern
);
537 void *salloc(size_t size
);
538 void *csalloc(size_t nmemb
, size_t size
);
540 void spreserve(void);
541 char *savestr(const char *str
);
542 char *savestrbuf(const char *sbuf
, size_t sbuf_len
);
543 char *save2str(const char *str
, const char *old
);
544 char *savecat(const char *s1
, const char *s2
);
546 struct str
*str_concat_csvl(struct str
*self
, ...);
549 FILE *Ftemp(char **fn
, char *prefix
, char *mode
, int bits
, int register_file
);
550 void Ftfree(char **fn
);
554 int thread(void *vp
);
555 int unthread(void *vp
);
556 struct message
*next_in_thread(struct message
*mp
);
557 struct message
*prev_in_thread(struct message
*mp
);
558 struct message
*this_in_thread(struct message
*mp
, long n
);
560 int ccollapse(void *v
);
561 int cuncollapse(void *v
);
562 void uncollapse1(struct message
*m
, int always
);
565 int grabh(struct header
*hp
, enum gfield gflags
, int subjfirst
);
566 char *readtty(char *prefix
, char *string
);
570 void findmail(char *user
, int force
, char *buf
, int size
);
572 char *username(void);
575 void assign(const char *name
, const char *value
);
576 char *vcopy(const char *str
);
577 char *value(const char *name
);
578 struct grouphead
*findgroup(char *name
);
579 void printgroup(char *name
);
580 int hash(const char *name
);
581 int unset_internal(const char *name
);
582 void remove_group(const char *name
);