Rocco Rutte:
[apps/madmutt.git] / mx.h
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
4  * Copyright (C) 1999-2002 Thomas Roessler <roessler@does-not-exist.org>
5  *
6  * This file is part of mutt-ng, see http://www.muttng.org/.
7  * It's licensed under the GNU General Public License,
8  * please see the file GPL in the top level source directory.
9  */
10
11 /*
12  * mailbox abstraction
13  * when adding code dealing with folders or whatever,
14  * please use these only
15  */
16
17 #ifndef _MX_H
18 #define _MX_H
19
20 /*
21  * supported mailbox formats
22  * in mx_init() the registration order must be exactly as given here!!!1!
23  */
24 enum {
25   M_MBOX = 1,
26   M_MMDF,
27   M_MH,
28   M_MAILDIR
29 #ifdef USE_IMAP
30     , M_IMAP
31 #endif
32 #ifdef USE_POP
33     , M_POP
34 #endif
35 #ifdef USE_NNTP
36     , M_NNTP
37 #endif
38 #ifdef USE_COMPRESSED
39     , M_COMPRESSED
40 #endif
41 };
42
43 typedef struct {
44   /* folder magic */
45   int type;
46   /* may we stat() it? */
47   unsigned int local : 1;
48   /* tests if given path is of its magic */
49   int (*mx_is_magic) (const char*);
50   /* tests if folder is empty */
51   int (*mx_check_empty) (const char*);
52   /* test for access */
53   int (*mx_access) (const char*, int);
54   /* read mailbox into ctx structure */
55   int (*mx_open_mailbox) (CONTEXT*);
56 } mx_t;
57
58 /* called from main: init all folder types */
59 void mx_init (void);
60
61 /* flags for mx_open_mailbox() */
62 #define M_NOSORT        (1<<0)  /* do not sort the mailbox after opening it */
63 #define M_APPEND        (1<<1)  /* open mailbox for appending messages */
64 #define M_READONLY      (1<<2)  /* open in read-only mode */
65 #define M_QUIET         (1<<3)  /* do not print any messages */
66 #define M_NEWFOLDER     (1<<4)  /* create a new folder - same as M_APPEND, but uses
67                                  * safe_fopen() for mbox-style folders.
68                                  */
69
70 /* mx_open_new_message() */
71 #define M_ADD_FROM      1       /* add a From_ line */
72
73 #define MAXLOCKATTEMPT 5
74
75 /* return values from mx_check_mailbox() */
76 enum {
77   M_NEW_MAIL = 1,               /* new mail received in mailbox */
78   M_LOCKED,                     /* couldn't lock the mailbox */
79   M_REOPENED,                   /* mailbox was reopened */
80   M_FLAGS                       /* nondestructive flags change (IMAP) */
81 };
82
83 typedef struct {
84   FILE *fp;                     /* pointer to the message data */
85   char *path;                   /* path to temp file */
86   short magic;                  /* type of mailbox this message belongs to */
87   short write;                  /* nonzero if message is open for writing */
88   struct {
89     unsigned read:1;
90     unsigned flagged:1;
91     unsigned replied:1;
92   } flags;
93   time_t received;              /* the time at which this message was received */
94 } MESSAGE;
95
96 WHERE short DefaultMagic INITVAL (M_MBOX);
97
98 CONTEXT *mx_open_mailbox (const char *, int, CONTEXT *);
99
100 MESSAGE *mx_open_message (CONTEXT *, int);
101 MESSAGE *mx_open_new_message (CONTEXT *, HEADER *, int);
102
103 void mx_fastclose_mailbox (CONTEXT *);
104
105 int mx_close_mailbox (CONTEXT *, int *);
106 int mx_sync_mailbox (CONTEXT *, int *);
107 int mx_commit_message (MESSAGE *, CONTEXT *);
108 int mx_close_message (MESSAGE **);
109 int mx_get_magic (const char *);
110 int mx_set_magic (const char *);
111 int mx_check_mailbox (CONTEXT *, int *, int);
112
113 int mx_access (const char *, int);
114 int mx_check_empty (const char *);
115
116 void mx_alloc_memory (CONTEXT *);
117 void mx_update_context (CONTEXT *, int);
118 void mx_update_tables (CONTEXT *, int);
119
120 int mx_lock_file (const char *, int, int, int, int);
121 int mx_unlock_file (const char *path, int fd, int dot);
122
123 #endif /* !_MX_H */