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 char *savestr(const char *str
);
43 char *savestrbuf(const char *sbuf
, size_t sbuf_len
);
44 char *save2str(const char *str
, const char *old
);
45 char *savecat(const char *s1
, const char *s2
);
46 void panic(const char *format
, ...);
49 void touch(struct message
*mp
);
50 int is_dir(char *name
);
51 int argcount(char **argv
);
52 void i_strcpy(char *dest
, const char *src
, int size
);
53 char *i_strdup(const char *src
);
54 void makelow(char *cp
);
55 int substr(const char *str
, const char *sub
);
56 char *colalign(const char *cp
, int col
, int fill
);
57 void try_pager(FILE *fp
);
60 void alter(char *name
);
61 int blankline(char *linebuf
);
62 int anyof(char *s1
, char *s2
);
63 int is_prefix(const char *as1
, const char *as2
);
64 char *last_at_before_slash(const char *sp
);
65 enum protocol
which_protocol(const char *name
);
66 const char *protfile(const char *xcp
);
67 char *protbase(const char *cp
);
68 int disconnected(const char *file
);
69 unsigned pjw(const char *cp
);
70 long nextprime(long n
);
71 char *strenc(const char *cp
);
72 char *strdec(const char *cp
);
74 char *md5tohex(const void *vp
);
75 char *cram_md5_string(const char *user
, const char *pass
, const char *b64
);
78 char *getpassword(struct termios
*otio
, int *reset_tio
, const char *query
);
79 void transflags(struct message
*omessage
, long omsgCount
, int transparent
);
80 char *getrandstring(size_t length
);
81 void out_of_memory(void);
82 void *smalloc(size_t s
);
83 void *srealloc(void *v
, size_t s
);
84 void *scalloc(size_t nmemb
, size_t size
);
85 char *sstpcpy(char *dst
, const char *src
);
86 char *sstrdup(const char *cp
);
87 enum okay
makedir(const char *name
);
88 enum okay
cwget(struct cw
*cw
);
89 enum okay
cwret(struct cw
*cw
);
90 void cwrelse(struct cw
*cw
);
91 void makeprint(struct str
*in
, struct str
*out
);
92 char *prstr(const char *s
);
93 int prout(const char *s
, size_t sz
, FILE *fp
);
94 int putuc(int u
, int c
, FILE *fp
);
95 int asccasecmp(const char *s1
, const char *s2
);
96 int ascncasecmp(const char *s1
, const char *s2
, size_t sz
);
97 char *asccasestr(const char *haystack
, const char *xneedle
);
99 char *strtob64(const char *p
);
100 char *memtob64(const void *vp
, size_t isz
);
101 size_t mime_write_tob64(struct str
*in
, FILE *fo
, int is_header
);
102 void mime_fromb64(struct str
*in
, struct str
*out
, int is_text
);
103 void mime_fromb64_b(struct str
*in
, struct str
*out
, int is_text
, FILE *f
);
105 enum okay
getcache1(struct mailbox
*mp
, struct message
*m
,
106 enum needspec need
, int setflags
);
107 enum okay
getcache(struct mailbox
*mp
, struct message
*m
, enum needspec need
);
108 void putcache(struct mailbox
*mp
, struct message
*m
);
109 void initcache(struct mailbox
*mp
);
110 void purgecache(struct mailbox
*mp
, struct message
*m
, long mc
);
111 void delcache(struct mailbox
*mp
, struct message
*m
);
112 enum okay
cache_setptr(int transparent
);
113 enum okay
cache_list(struct mailbox
*mp
, const char *base
, int strip
, FILE *fp
);
114 enum okay
cache_remove(const char *name
);
115 enum okay
cache_rename(const char *old
, const char *new);
116 unsigned long cached_uidvalidity(struct mailbox
*mp
);
117 FILE *cache_queue(struct mailbox
*mp
);
118 enum okay
cache_dequeue(struct mailbox
*mp
);
120 char *get_pager(void);
121 int headers(void *v
);
124 int screensize(void);
126 void printhead(int mesg
, FILE *f
, int threaded
);
128 int pcmdlist(void *v
);
129 char *laststring(char *linebuf
, int *flag
, int strip
);
135 int pipecmd(void *v
);
136 int Pipecmd(void *v
);
140 int folders(void *v
);
145 int copycmd(void *v
);
146 int Copycmd(void *v
);
149 int cdecrypt(void *v
);
150 int cDecrypt(void *v
);
153 int deltype(void *v
);
154 int undeletecmd(void *v
);
155 int retfield(void *v
);
156 int igfield(void *v
);
157 int saveretfield(void *v
);
158 int saveigfield(void *v
);
159 int fwdretfield(void *v
);
160 int fwdigfield(void *v
);
161 int unignore(void *v
);
162 int unretain(void *v
);
163 int unsaveignore(void *v
);
164 int unsaveretain(void *v
);
165 int unfwdignore(void *v
);
166 int unfwdretain(void *v
);
172 int respond(void *v
);
173 int respondall(void *v
);
174 int respondsender(void *v
);
175 int followup(void *v
);
176 int followupall(void *v
);
177 int followupsender(void *v
);
178 int preserve(void *v
);
181 int messize(void *v
);
186 int ungroup(void *v
);
189 int Respond(void *v
);
190 int Followup(void *v
);
191 int forwardcmd(void *v
);
192 int Forwardcmd(void *v
);
194 int elsecmd(void *v
);
195 int endifcmd(void *v
);
196 int alternates(void *v
);
197 int resendcmd(void *v
);
198 int Resendcmd(void *v
);
199 int newmail(void *v
);
200 int shortcut(void *v
);
201 struct shortcut
*get_shortcut(const char *str
);
202 int unshortcut(void *v
);
203 struct oldaccount
*get_oldaccount(const char *name
);
204 int account(void *v
);
206 int cunflag(void *v
);
207 int canswered(void *v
);
208 int cunanswered(void *v
);
210 int cundraft(void *v
);
212 int cunkill(void *v
);
215 int cremove(void *v
);
216 int crename(void *v
);
219 struct attachment
*edit_attachments(struct attachment
*attach
);
220 struct attachment
*add_attachment(struct attachment
*attach
, char *file
,
222 FILE *collect(struct header
*hp
, int printheaders
, struct message
*mp
,
223 char *quotefile
, int doprefix
, int tflag
);
224 void savedeadletter(FILE *fp
);
226 int fcntl_lock(int fd
, int type
);
227 int dot_lock(const char *fname
, int fd
, int pollinterval
, FILE *fp
,
229 void dot_unlock(const char *fname
);
233 FILE *run_editor(FILE *fp
, off_t size
, int type
, int readonly
,
234 struct header
*hp
, struct message
*mp
, enum sendaction action
,
235 sighandler_type oldint
);
237 void setptr(FILE *ibuf
, off_t offset
);
238 int putline(FILE *obuf
, char *linebuf
, size_t count
);
239 #define readline(a, b, c) readline_restart(a, b, c, 0)
240 int readline_restart(FILE *ibuf
, char **linebuf
, size_t *linesize
, size_t n
);
241 FILE *setinput(struct mailbox
*mp
, struct message
*m
, enum needspec need
);
242 struct message
*setdot(struct message
*mp
);
245 void relsesigs(void);
246 off_t
fsize(FILE *iob
);
247 char *expand(char *name
);
248 int getfold(char *name
, int size
);
249 char *getdeadletter(void);
250 char *fgetline(char **line
, size_t *linesize
, size_t *count
,
251 size_t *llen
, FILE *fp
, int appendnl
);
252 void newline_appended(void);
253 enum okay
get_body(struct message
*mp
);
254 int sclose(struct sock
*sp
);
255 enum okay
swrite(struct sock
*sp
, const char *data
);
256 enum okay
swrite1(struct sock
*sp
, const char *data
, int sz
, int use_buffer
);
257 int sgetline(char **line
, size_t *linesize
, size_t *linelen
, struct sock
*sp
);
258 enum okay
sopen(const char *xserver
, struct sock
*sp
, int use_ssl
,
259 const char *uhp
, const char *portstr
, int verbose
);
261 char *getname(int uid
);
262 int getuserid(char *name
);
264 int getopt(int argc
, char *const argv
[], const char *optstring
);
266 int is_head(char *linebuf
, size_t linelen
);
267 void parse(char *line
, size_t linelen
, struct headline
*hl
, char *pbuf
);
268 void extract_header(FILE *fp
, struct header
*hp
);
269 #define hfield(a, b) hfield_mult(a, b, 1)
270 char *hfield_mult(char *field
, struct message
*mp
, int mult
);
271 char *thisfield(const char *linebuf
, const char *field
);
272 char *nameof(struct message
*mp
, int reptype
);
273 char *skip_comment(const char *cp
);
274 char *routeaddr(const char *name
);
275 char *skin(char *name
);
276 char *skinned_name(struct name
*np
);
277 char *realname(char *name
);
278 char *name1(struct message
*mp
, int reptype
);
279 int msgidcmp(const char *s1
, const char *s2
);
280 int is_ign(char *field
, size_t fieldlen
, struct ignoretab ignore
[2]);
281 int member(char *realfield
, struct ignoretab
*table
);
282 char *fakefrom(struct message
*mp
);
283 char *fakedate(time_t t
);
284 char *nexttoken(char *cp
);
285 time_t unixtime(char *from
);
286 time_t rfctime(char *date
);
287 time_t combinetime(int year
, int month
, int day
,
288 int hour
, int minute
, int second
);
289 void substdate(struct message
*m
);
290 int check_from_and_sender(struct name
*fromfield
, struct name
*senderfield
);
291 char *getsender(struct message
*m
);
293 enum okay
imap_noop(void);
294 enum okay
imap_select(struct mailbox
*mp
, off_t
*size
, int *count
,
296 int imap_setfile(const char *xserver
, int newmail
, int isedit
);
297 enum okay
imap_header(struct message
*m
);
298 enum okay
imap_body(struct message
*m
);
299 void imap_getheaders(int bot
, int top
);
300 void imap_quit(void);
301 enum okay
imap_undelete(struct message
*m
, int n
);
302 enum okay
imap_unread(struct message
*m
, int n
);
303 int imap_imap(void *vp
);
304 int imap_newmail(int autoinc
);
305 enum okay
imap_append(const char *xserver
, FILE *fp
);
306 void imap_folders(const char *name
, int strip
);
307 enum okay
imap_copy(struct message
*m
, int n
, const char *name
);
308 enum okay
imap_search1(const char *spec
, int f
);
309 int imap_thisaccount(const char *cp
);
310 enum okay
imap_remove(const char *name
);
311 enum okay
imap_rename(const char *old
, const char *new);
312 enum okay
imap_dequeue(struct mailbox
*mp
, FILE *fp
);
313 int cconnect(void *vp
);
314 int cdisconnect(void *vp
);
315 int ccache(void *vp
);
316 time_t imap_read_date_time(const char *cp
);
317 time_t imap_read_date(const char *cp
);
318 const char *imap_make_date_time(time_t t
);
319 char *imap_quotestr(const char *s
);
320 char *imap_unquotestr(const char *s
);
323 enum okay
imap_search(const char *spec
, int f
);
327 int cungood(void *v
);
328 int cunjunk(void *v
);
329 int cclassify(void *v
);
330 int cprobability(void *v
);
332 int setfile(char *name
, int newmail
);
333 int newmailinfo(int omsgCount
);
335 int execute(char *linebuf
, int contxt
, size_t linesize
);
336 void setmsize(int sz
);
338 void announce(int printheaders
);
339 int newfileinfo(void);
340 int getmdot(int newmail
);
341 int pversion(void *v
);
342 void load(char *name
);
343 void initbox(const char *name
);
345 int getmsglist(char *buf
, int *vector
, int flags
);
346 int getrawlist(const char *line
, size_t linesize
,
347 char **argv
, int argc
, int echolist
);
348 int first(int f
, int m
);
349 void mark(int mesg
, int f
);
351 int zwrite(void *cookie
, const char *wbp
, int num
);
352 int zfree(void *cookie
);
353 int zread(void *cookie
, char *rbp
, int num
);
354 void *zalloc(FILE *fp
);
356 int cdefine(void *v
);
357 int define1(const char *name
, int account
);
360 int callaccount(const char *name
);
361 int callhook(const char *name
, int newmail
);
362 int listaccounts(FILE *fp
);
363 int cdefines(void *v
);
364 void delaccount(const char *name
);
366 int maildir_setfile(const char *name
, int newmail
, int isedit
);
367 void maildir_quit(void);
368 enum okay
maildir_append(const char *name
, FILE *fp
);
369 enum okay
maildir_remove(const char *name
);
371 int main(int argc
, char *argv
[]);
373 int mime_name_invalid(struct name
*np
, int putmsg
);
374 struct name
*checkaddrs(struct name
*np
);
375 char *gettcharset(void);
376 char *need_hdrconv(struct header
*hp
, enum gfield w
);
378 iconv_t
iconv_open_ft(const char *tocode
, const char *fromcode
);
379 size_t iconv_ft(iconv_t cd
, char **inb
, size_t *inbleft
,
380 char **outb
, size_t *outbleft
, int tolerant
);
381 #endif /* HAVE_ICONV */
382 enum mimeenc
mime_getenc(char *h
);
383 int mime_getcontent(char *h
);
384 char *mime_getparam(char *param
, char *h
);
385 char *mime_getboundary(char *h
);
386 char *mime_filecontent(char *name
);
387 int get_mime_convert(FILE *fp
, char **contenttype
, char **charset
,
388 enum mimeclean
*isclean
, int dosign
);
389 void mime_fromhdr(struct str
*in
, struct str
*out
, enum tdflags flags
);
390 char *mime_fromaddr(char *name
);
391 size_t prefixwrite(void *ptr
, size_t size
, size_t nmemb
, FILE *f
,
392 char *prefix
, size_t prefixlen
);
393 size_t mime_write(void *ptr
, size_t size
, FILE *f
,
394 enum conversion convert
, enum tdflags dflags
,
395 char *prefix
, size_t prefixlen
,
396 char **rest
, size_t *restsize
);
398 struct name
*nalloc(char *str
, enum gfield ntype
);
399 struct name
*ndup(struct name
*np
, enum gfield ntype
);
400 struct name
*extract(char *line
, enum gfield ntype
);
401 struct name
*sextract(char *line
, enum gfield ntype
);
402 char *detract(struct name
*np
, enum gfield ntype
);
403 struct name
*outof(struct name
*names
, FILE *fo
, struct header
*hp
);
404 int is_fileaddr(char *name
);
405 struct name
*usermap(struct name
*names
);
406 struct name
*cat(struct name
*n1
, struct name
*n2
);
407 char **unpack(struct name
*np
);
408 struct name
*elide(struct name
*names
);
409 int count(struct name
*np
);
410 struct name
*delete_alternates(struct name
*np
);
411 int is_myname(char *name
);
414 enum okay
ssl_open(const char *server
, struct sock
*sp
, const char *uhp
);
415 void nss_gen_err(const char *fmt
, ...);
419 enum okay
ssl_open(const char *server
, struct sock
*sp
, const char *uhp
);
420 void ssl_gen_err(const char *fmt
, ...);
421 #endif /* USE_OPENSSL */
422 int cverify(void *vp
);
423 FILE *smime_sign(FILE *ip
, struct header
*);
424 FILE *smime_encrypt(FILE *ip
, const char *certfile
, const char *to
);
425 struct message
*smime_decrypt(struct message
*m
, const char *to
,
426 const char *cc
, int signcall
);
427 enum okay
smime_certsave(struct message
*m
, int n
, FILE *op
);
429 enum okay
pop3_noop(void);
430 int pop3_setfile(const char *server
, int newmail
, int isedit
);
431 enum okay
pop3_header(struct message
*m
);
432 enum okay
pop3_body(struct message
*m
);
433 void pop3_quit(void);
435 sighandler_type
safe_signal(int signum
, sighandler_type handler
);
436 FILE *safe_fopen(const char *file
, const char *mode
, int *omode
);
437 FILE *Fopen(const char *file
, const char *mode
);
438 FILE *Fdopen(int fd
, const char *mode
);
439 int Fclose(FILE *fp
);
440 FILE *Zopen(const char *file
, const char *mode
, int *compression
);
441 FILE *Popen(const char *cmd
, const char *mode
, const char *shell
, int newfd1
);
442 int Pclose(FILE *ptr
);
443 void close_all_files(void);
444 int run_command(char *cmd
, sigset_t
*mask
, int infd
, int outfd
,
445 char *a0
, char *a1
, char *a2
);
446 int start_command(const char *cmd
, sigset_t
*mask
, int infd
, int outfd
,
447 const char *a0
, const char *a1
, const char *a2
);
448 void prepare_child(sigset_t
*nset
, int infd
, int outfd
);
449 void sigchild(int signo
);
450 void free_child(int pid
);
451 int wait_child(int pid
);
453 int quitcmd(void *v
);
456 enum okay
makembox(void);
457 int savequitflags(void);
458 void restorequitflags(int);
460 char *foldergets(char **s
, size_t *size
, size_t *count
, size_t *llen
,
463 #define send(a, b, c, d, e, f) xsend(a, b, c, d, e, f)
464 int send(struct message
*mp
, FILE *obuf
, struct ignoretab
*doign
,
465 char *prefix
, enum sendaction action
, off_t
*stats
);
467 char *makeboundary(void);
468 int mail(struct name
*to
, struct name
*cc
, struct name
*bcc
,
469 struct name
*smopts
, char *subject
, struct attachment
*attach
,
470 char *quotefile
, int recipient_record
, int tflag
, int Eflag
);
471 int sendmail(void *v
);
472 int Sendmail(void *v
);
473 enum okay
mail1(struct header
*hp
, int printheaders
, struct message
*quote
,
474 char *quotefile
, int recipient_record
, int doprefix
, int tflag
,
476 int mkdate(FILE *fo
, const char *field
);
477 int puthead(struct header
*hp
, FILE *fo
, enum gfield w
,
478 enum sendaction action
, enum conversion convert
,
479 char *contenttype
, char *charset
);
480 enum okay
resend_msg(struct message
*mp
, struct name
*to
, int add_resent
);
482 char *nodename(int mayoverride
);
483 char *myaddrs(struct header
*hp
);
484 char *myorigin(struct header
*hp
);
485 char *smtp_auth_var(const char *type
, const char *addr
);
486 int smtp_mta(char *server
, struct name
*to
, FILE *fi
, struct header
*hp
,
487 const char *user
, const char *password
, const char *skinned
);
489 void ssl_set_vrfy_level(const char *uhp
);
490 enum okay
ssl_vrfy_decide(void);
491 char *ssl_method_string(const char *uhp
);
492 enum okay
smime_split(FILE *ip
, FILE **hp
, FILE **bp
, long xcount
, int keep
);
493 FILE *smime_sign_assemble(FILE *hp
, FILE *bp
, FILE *sp
);
494 FILE *smime_encrypt_assemble(FILE *hp
, FILE *yp
);
495 struct message
*smime_decrypt_assemble(struct message
*m
, FILE *hp
, FILE *bp
);
496 int ccertsave(void *v
);
497 enum okay
rfc2595_hostname_match(const char *host
, const char *pattern
);
499 void *salloc(size_t size
);
500 void *csalloc(size_t nmemb
, size_t size
);
502 void spreserve(void);
504 FILE *Ftemp(char **fn
, char *prefix
, char *mode
, int bits
, int register_file
);
505 void Ftfree(char **fn
);
508 int thread(void *vp
);
509 int unthread(void *vp
);
510 struct message
*next_in_thread(struct message
*mp
);
511 struct message
*prev_in_thread(struct message
*mp
);
512 struct message
*this_in_thread(struct message
*mp
, long n
);
514 int ccollapse(void *v
);
515 int cuncollapse(void *v
);
516 void uncollapse1(struct message
*m
, int always
);
518 int grabh(struct header
*hp
, enum gfield gflags
, int subjfirst
);
519 char *readtty(char *prefix
, char *string
);
522 void findmail(char *user
, int force
, char *buf
, int size
);
524 char *username(void);
526 void assign(const char *name
, const char *value
);
527 char *vcopy(const char *str
);
528 char *value(const char *name
);
529 struct grouphead
*findgroup(char *name
);
530 void printgroup(char *name
);
531 int hash(const char *name
);
532 int unset_internal(const char *name
);
533 void remove_group(const char *name
);