Blame view

mail/mail.h 16.6 KB
1
/* GNU Mailutils -- a suite of utilities for electronic mail
2 3
   Copyright (C) 1999, 2000, 2001, 2002, 2005, 2006, 2007, 2009, 2010
   Free Software Foundation, Inc.
4

5
   GNU Mailutils is free software; you can redistribute it and/or modify
6
   it under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; either version 3, or (at your option)
8 9
   any later version.

10
   GNU Mailutils is distributed in the hope that it will be useful,
11 12 13 14 15
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
16
   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
17 18 19 20 21 22 23

#ifndef _MAIL_H
#define _MAIL_H 1

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
24 25

#ifdef DMALLOC
Sergey Poznyakoff authored
26
# include <dmalloc.h>
27 28
#endif

29 30 31
#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#endif
32
#include <errno.h>
33
#include <limits.h>
34 35 36
#ifndef _GNU_SOURCE
# define _GNU_SOURCE
#endif
37 38 39 40
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
41 42 43
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
44 45
#include <sys/wait.h>
#include <sys/types.h>
46
#include <stdarg.h>
47
#include <signal.h>
Sergey Poznyakoff authored
48 49

#include <confpaths.h>
50

Sergey Poznyakoff authored
51
#include <xalloc.h>
52

53
#ifdef HAVE_READLINE_READLINE_H
54 55
# include <readline/readline.h>
# include <readline/history.h>
56
#endif
57

58
#include <mailutils/address.h>
59
#include <mailutils/assoc.h>
60 61 62
#include <mailutils/attribute.h>
#include <mailutils/body.h>
#include <mailutils/debug.h>
63
#include <mailutils/errno.h>
64
#include <mailutils/error.h>
65 66
#include <mailutils/envelope.h>
#include <mailutils/filter.h>
67
#include <mailutils/header.h>
68
#include <mailutils/iterator.h>
69 70 71 72
#include <mailutils/list.h>
#include <mailutils/mailbox.h>
#include <mailutils/mailer.h>
#include <mailutils/message.h>
73
#include <mailutils/util.h>
74 75 76
#include <mailutils/registrar.h>
#include <mailutils/stream.h>
#include <mailutils/url.h>
77
#include <mailutils/nls.h>
Sergey Poznyakoff authored
78
#include <mailutils/tls.h>
79
#include <mailutils/argcv.h>
80
#include <mailutils/wordsplit.h>
81 82
#include <mailutils/cctype.h>
#include <mailutils/cstr.h>
83
#include <mailutils/io.h>
84
#include <mailutils/stdstream.h>
85
#include <mailutils/prog.h>
86

87 88 89 90
#ifdef __cplusplus
extern "C" {
#endif

Jakob Kaivo authored
91
/* Type definitions */
92
#ifndef function_t
93
typedef int function_t (int, char **);
Jakob Kaivo authored
94 95
#endif

96
/* Values for mail_command_entry.flags */
97 98 99 100 101
#define EF_REG    0x00    /* Regular command */
#define EF_FLOW   0x01    /* Flow control command */
#define EF_SEND   0x02    /* Send command */
#define EF_HIDDEN 0x04    /* Hiddent command */
  
102
typedef struct compose_env
103
{
104
  mu_header_t header;   /* The message headers */
105
  mu_stream_t compstr;    /* Temporary compose stream */
106 107 108 109
  char **outfiles;   /* Names of the output files. The message is to be
		        saved in each of these. */
  int nfiles;        /* Number of output files */
} compose_env_t;
110

111 112 113 114 115 116 117 118 119 120 121 122 123 124
#define MAIL_COMMAND_COMMON_MEMBERS \
  const char *shortname;\
  const char *longname;\
  const char *synopsis
  
struct mail_command
{
  MAIL_COMMAND_COMMON_MEMBERS;
};

struct mail_command_entry
{
  MAIL_COMMAND_COMMON_MEMBERS;
  int flags;
125 126
  int (*func) (int, char **);
  char **(*command_completion) (int argc, char **argv, int ws);
127 128 129 130
};

struct mail_escape_entry
{
131 132 133
  const char *shortname;
  const char *longname;
  const char *synopsis;
134
  int (*escfunc) (int, char **, compose_env_t *);
135 136
};

137
enum mailvar_type
138
  {
139 140 141 142 143 144 145 146 147 148 149 150 151 152
    mailvar_type_whatever,
    mailvar_type_number,
    mailvar_type_string,
    mailvar_type_boolean
  };

union mailvar_value
{
  char *string;
  int number;
  int bool;
};

struct mailvar_variable
153
{
154 155
  char *name;
  enum mailvar_type type;
156
  int set;
157
  union mailvar_value value;
158 159
};

160 161 162 163
typedef struct message_set msgset_t;

struct message_set
{
164 165 166 167
  msgset_t *next;       /* Link to the next message set */
  unsigned int npart;   /* Number of parts in this set */
  size_t *msg_part;     /* Array of part numbers: msg_part[0] is the 
                           message number */
168
};
169

170
typedef int (*msg_handler_t) (msgset_t *mp, mu_message_t mesg, void *data);
171

Jakob Kaivo authored
172
/* Global variables and constants*/
173
extern mu_mailbox_t mbox;
174
extern size_t total;
175
extern int interactive;
176
extern const char *program_version;
177 178

/* Functions */
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
extern int mail_alias (int argc, char **argv);
extern int mail_alt (int argc, char **argv);	/* command alternates */
extern int mail_cd (int argc, char **argv);
extern int mail_copy (int argc, char **argv);
extern int mail_decode (int argc, char **argv);
extern int mail_delete (int argc, char **argv);
extern int mail_discard (int argc, char **argv);
extern int mail_dp (int argc, char **argv);
extern int mail_echo (int argc, char **argv);
extern int mail_edit (int argc, char **argv);
extern int mail_else (int argc, char **argv);
extern int mail_endif (int argc, char **argv);
extern int mail_exit (int argc, char **argv);
extern int mail_file (int argc, char **argv);
extern int mail_folders (int argc, char **argv);
extern int mail_followup (int argc, char **argv);
extern int mail_from (int argc, char **argv);
196
extern int mail_from0 (msgset_t *mspec, mu_message_t msg, void *data);
197 198
extern void mail_compile_headline (struct mailvar_variable *var);

199 200 201 202 203 204 205 206 207 208
extern int mail_headers (int argc, char **argv);
extern int mail_hold (int argc, char **argv);
extern int mail_help (int argc, char **argv);
extern int mail_if (int argc, char **argv);
extern int mail_inc (int argc, char **argv);
extern int mail_list (int argc, char **argv);
extern int mail_send (int argc, char **argv);	/* command mail */
extern int mail_mbox (int argc, char **argv);
extern int mail_next (int argc, char **argv);
extern int mail_nounfold (int argc, char **argv);
209
extern int mail_variable (int argc, char **argv);
210 211 212 213 214 215 216 217 218 219
extern int mail_pipe (int argc, char **argv);
extern int mail_previous (int argc, char **argv);
extern int mail_print (int argc, char **argv);
extern int mail_quit (int argc, char **argv);
extern int mail_reply (int argc, char **argv);
extern int mail_retain (int argc, char **argv);
extern int mail_save (int argc, char **argv);
extern int mail_sendheader (int argc, char **argv);
extern int mail_set (int argc, char **argv);
extern int mail_shell (int argc, char **argv);
220
extern int mail_execute (int shell, char *progname, int argc, char **argv);
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
extern int mail_size (int argc, char **argv);
extern int mail_source (int argc, char **argv);
extern int mail_summary (int argc, char **argv);
extern int mail_tag (int argc, char **argv);
extern int mail_top (int argc, char **argv);
extern int mail_touch (int argc, char **argv);
extern int mail_unalias (int argc, char **argv);
extern int mail_undelete (int argc, char **argv);
extern int mail_unfold (int argc, char **argv);
extern int mail_unset (int argc, char **argv);
extern int mail_version (int argc, char **argv);
extern int mail_visual (int argc, char **argv);
extern int mail_warranty (int argc, char **argv);
extern int mail_write (int argc, char **argv);
extern int mail_z (int argc, char **argv);
extern int mail_eq (int argc, char **argv);	/* command = */
extern int mail_setenv (int argc, char **argv);
238 239
extern int mail_envelope (int argc, char **argv);
extern int print_envelope (msgset_t *mspec, mu_message_t msg, void *data);
240
extern int mail_struct (int argc, char **argv);
241 242 243 244 245 246 247 248

extern int if_cond (void);

extern void mail_mainloop (char *(*input) (void *, int), void *closure, int do_history);
extern int mail_copy0 (int argc, char **argv, int mark);
extern int mail_send0 (compose_env_t *env, int save_to);
extern void free_env_headers (compose_env_t *env);

249
/*extern void print_message (mu_message_t mesg, char *prefix, int all_headers, FILE *file);*/
250 251

extern int mail_mbox_commit (void);
252
extern int mail_is_my_name (const char *name);
253 254
extern void mail_set_my_name (char *name);
extern char *mail_whoami (void);
255 256
extern int mail_header_is_visible (const char *str);
extern int mail_header_is_unfoldable (const char *str);
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
extern int mail_mbox_close (void);
extern char *mail_expand_name (const char *name);

extern void send_append_header (char *text);
extern void send_append_header2 (char *name, char *value, int mode);

extern int escape_shell (int argc, char **argv, compose_env_t *env);
extern int escape_command (int argc, char **argv, compose_env_t *env);
extern int escape_help (int argc, char **argv, compose_env_t *env);
extern int escape_sign (int argc, char **argv, compose_env_t *env);
extern int escape_bcc (int argc, char **argv, compose_env_t *env);
extern int escape_cc (int argc, char **argv, compose_env_t *env);
extern int escape_deadletter (int argc, char **argv, compose_env_t *env);
extern int escape_editor (int argc, char **argv, compose_env_t *env);
extern int escape_print (int argc, char **argv, compose_env_t *env);
extern int escape_headers (int argc, char **argv, compose_env_t *env);
extern int escape_insert (int argc, char **argv, compose_env_t *env);
extern int escape_quote (int argc, char **argv, compose_env_t *env);
extern int escape_type_input (int argc, char **argv, compose_env_t *env);
extern int escape_read (int argc, char **argv, compose_env_t *env);
extern int escape_subj (int argc, char **argv, compose_env_t *env);
extern int escape_to (int argc, char **argv, compose_env_t *env);
extern int escape_visual (int argc, char **argv, compose_env_t *env);
extern int escape_write (int argc, char **argv, compose_env_t *env);
extern int escape_exit (int argc, char **argv, compose_env_t *env);
extern int escape_pipe (int argc, char **argv, compose_env_t *env);
283

Sergey Poznyakoff authored
284
/* Cursor */
285 286 287
extern void set_cursor (unsigned value);
extern size_t get_cursor (void);
extern void page_invalidate (int hard);
Sergey Poznyakoff authored
288
extern void cond_page_invalidate (size_t value);
289 290 291
extern void page_do (msg_handler_t func, void *data);
extern size_t page_move (off_t offset);
extern int is_current_message (size_t n);
Sergey Poznyakoff authored
292

293
/* msgsets */
294 295 296 297 298 299 300 301 302 303 304 305
extern void msgset_free (msgset_t *msg_set);
extern msgset_t *msgset_make_1 (size_t number);
extern msgset_t *msgset_append (msgset_t *one, msgset_t *two);
extern msgset_t *msgset_range (int low, int high);
extern msgset_t *msgset_expand (msgset_t *set, msgset_t *expand_by);
extern msgset_t *msgset_dup (const msgset_t *set);
extern int msgset_parse (const int argc, char **argv,
			 int flags, msgset_t **mset);
extern int msgset_member (msgset_t *set, size_t n);
extern msgset_t *msgset_negate (msgset_t *set);
extern size_t msgset_count (msgset_t *set);

306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326

#define MDHINT_SELECTED_HEADERS 0x1

struct mime_descend_closure
{
  int hints;
  const msgset_t *msgset;
  mu_message_t message;
  const char *type;
  const char *encoding;
  const struct mime_descend_closure *parent;
};

typedef int (*mime_descend_fn) (struct mime_descend_closure *closure,
				void *data);

extern int mime_descend (struct mime_descend_closure *closure,
			 mime_descend_fn fun, void *data);



327
extern int util_do_command (const char *cmd, ...) MU_PRINTFLIKE(1,2);
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352

extern int util_foreach_msg (int argc, char **argv, int flags,
			     msg_handler_t func, void *data);
extern size_t util_range_msg (size_t low, size_t high, int flags, 
			      msg_handler_t func, void *data);

extern function_t* util_command_get (const char *cmd);

extern void *util_find_entry (void *table, size_t nmemb, size_t size,
			      const char *cmd);
extern int util_help (void *table, size_t nmemb, size_t size, const char *word);
extern int util_command_list (void *table, size_t nmemb, size_t size);

extern const struct mail_command_entry *mail_find_command (const char *cmd);
extern const struct mail_escape_entry *mail_find_escape (const char *cmd);
extern int mail_command_help (const char *command);
extern int mail_escape_help (const char *command);
extern void mail_command_list (void);
extern const struct mail_command *mail_command_name (int i);

extern int util_getcols (void);
extern int util_getlines (void);
extern int util_screen_lines (void);
extern int util_screen_columns (void);
extern int util_get_crt (void);
353 354 355 356 357
extern struct mailvar_variable *mailvar_find_variable (const char *var, int create);
extern int mailvar_get (void *ptr, const char *variable,
			enum mailvar_type type, int warn);

extern void mailvar_print (int set);
358
extern void mailvar_variable_format (mu_stream_t,
359 360 361 362 363
				     const struct mailvar_variable *,
				     const char *defval);

#define MOPTF_OVERWRITE 0x001
#define MOPTF_QUIET     0x002
364
#define MOPTF_UNSET     0x004
365 366
extern int mailvar_set (const char *name, void *value,
		      enum mailvar_type type, int flags);
367 368 369 370 371 372
extern int util_isdeleted (size_t msgno);
extern char *util_get_homedir (void);
extern char *util_fullpath (const char *inpath);
extern char *util_folder_path (const char *name);
extern char *util_get_sender (int msgno, int strip);

373
extern void util_slist_print (mu_list_t list, int nl);
374
extern int util_slist_lookup (mu_list_t list, const char *str);
375 376 377 378
extern void util_slist_add (mu_list_t *list, char *value);
extern void util_slist_remove (mu_list_t *list, char *value);
extern void util_slist_destroy (mu_list_t *list);
extern char *util_slist_to_string (mu_list_t list, const char *delim);
379 380
extern void util_strcat (char **dest, const char *str);
extern char *util_outfolder_name (char *str);
381
extern void util_save_outgoing (mu_message_t msg, char *savefile);
382 383 384 385
extern int util_error_range (size_t msgno);
extern void util_noapp (void);
extern int util_tempfile (char **namep);
extern void util_msgset_iterate (msgset_t *msgset, 
386
                                 int (*fun) (mu_message_t, msgset_t *, void *), 
387
                                 void *closure);
388
extern int util_get_content_type (mu_header_t hdr, char **value, char **args);
389
extern int util_get_hdr_value (mu_header_t hdr, const char *name, char **value);
390
extern int util_merge_addresses (char **addr_str, const char *value);
391 392
extern int util_header_expand (mu_header_t *hdr);
extern int util_get_message (mu_mailbox_t mbox, size_t msgno, mu_message_t *msg);
393
void util_cache_command (mu_list_t *list, const char *fmt, ...) MU_PRINTFLIKE(2,3);
394
void util_run_cached_commands (mu_list_t *list);
395 396 397
const char *util_reply_prefix (void);
void util_rfc2047_decode (char **value);

398
void util_mark_read (mu_message_t msg);
399

400 401
const char *util_url_to_string (mu_url_t url);

402 403 404
mu_stream_t open_pager (size_t lines);

void format_msgset (mu_stream_t str, const msgset_t *msgset, size_t *count);
405

406 407
int is_address_field (const char *name);

408 409 410 411
extern int ml_got_interrupt (void);
extern void ml_clear_interrupt (void);
extern void ml_readline_init (void);
extern int ml_reread (const char *prompt, char **text);
412 413
extern char *ml_readline (const char *prompt);
extern char *ml_readline_with_intr (const char *prompt);
414

415
extern char *alias_expand (const char *name);
416
extern void alias_destroy (const char *name);
417

418
typedef struct alias_iterator *alias_iterator_t;
419 420 421 422
extern char *alias_find_first (const char *prefix, alias_iterator_t *itr);
extern const char *alias_iterate_next (alias_iterator_t itr);
extern const char *alias_iterate_first (const char *p, alias_iterator_t *itr);
extern void alias_iterate_end (alias_iterator_t *itr);
423

424 425
extern int mail_sender    (int argc, char **argv);
extern int mail_nosender  (int argc, char **argv);
426
extern mu_address_t get_sender_address (mu_message_t msg);
427

428 429 430 431
#define COMPOSE_APPEND      0
#define COMPOSE_REPLACE     1
#define COMPOSE_SINGLE_LINE 2

432
void compose_init (compose_env_t *env);
433 434
int compose_header_set (compose_env_t *env, const char *name,
		        const char *value, int replace);
435 436
char *compose_header_get (compose_env_t *env, char *name, char *defval);
void compose_destroy (compose_env_t *env);
437

438
#ifndef HAVE_READLINE_READLINE_H
439
extern char *readline (char *prompt);
440
#endif
441

442 443 444 445
/* Flags for util_get_message */
#define MSG_ALL       0
#define MSG_NODELETED 0x0001
#define MSG_SILENT    0x0002
Sergey Poznyakoff authored
446
#define MSG_COUNT     0x0004
447

448
/* Message attributes */
449
#define MAIL_ATTRIBUTE_MBOXED   0x0001
450 451 452 453 454
#define MAIL_ATTRIBUTE_PRESERVED 0x0002
#define MAIL_ATTRIBUTE_SAVED    0x0004
#define MAIL_ATTRIBUTE_TAGGED   0x0008
#define MAIL_ATTRIBUTE_SHOWN    0x0010
#define MAIL_ATTRIBUTE_TOUCHED  0x0020
455

456 457
extern void ml_attempted_completion_over (void);

458 459 460 461 462 463 464 465
#ifdef WITH_READLINE
extern char **file_compl (int argc, char **argv, int ws);
extern char **no_compl (int argc, char **argv, int ws);
extern char **msglist_compl (int argc, char **argv, int ws);
extern char **msglist_file_compl (int argc, char **argv, int ws);
extern char **dir_compl (int argc, char **argv, int ws);
extern char **command_compl (int argc, char **argv, int ws);
extern char **alias_compl (int argc, char **argv, int ws);
466
extern char **mailvar_set_compl (int argc, char **argv, int ws);
467
extern char **exec_compl (int argc, char **argv, int ws);
468 469 470 471 472 473 474 475 476
#else
# define file_compl NULL
# define no_compl NULL
# define msglist_compl NULL
# define msglist_file_compl NULL
# define dir_compl NULL
# define command_compl NULL
# define alias_compl NULL
# define var_compl NULL
477
# define exec_compl NULL     
Sergey Poznyakoff authored
478
# define mailvar_set_compl NULL
479 480
#endif

481 482 483 484 485
#ifdef __cplusplus
}
#endif

#endif /* _MAIL_H */