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 /* supported mailbox formats */
21 enum {
22   M_MBOX = 1,
23   M_MMDF,
24   M_MH,
25   M_MAILDIR
26 #ifdef USE_IMAP
27     , M_IMAP
28 #endif
29 #ifdef USE_POP
30     , M_POP
31 #endif
32 #ifdef USE_NNTP
33     , M_NNTP
34 #endif
35 #ifdef USE_COMPRESSED
36     , M_COMPRESSED
37 #endif
38 };
39
40 /* flags for mx_open_mailbox() */
41 #define M_NOSORT        (1<<0)  /* do not sort the mailbox after opening it */
42 #define M_APPEND        (1<<1)  /* open mailbox for appending messages */
43 #define M_READONLY      (1<<2)  /* open in read-only mode */
44 #define M_QUIET         (1<<3)  /* do not print any messages */
45 #define M_NEWFOLDER     (1<<4)  /* create a new folder - same as M_APPEND, but uses
46                                  * safe_fopen() for mbox-style folders.
47                                  */
48
49 /* mx_open_new_message() */
50 #define M_ADD_FROM      1       /* add a From_ line */
51
52 #define MAXLOCKATTEMPT 5
53
54 /* return values from mx_check_mailbox() */
55 enum {
56   M_NEW_MAIL = 1,               /* new mail received in mailbox */
57   M_LOCKED,                     /* couldn't lock the mailbox */
58   M_REOPENED,                   /* mailbox was reopened */
59   M_FLAGS                       /* nondestructive flags change (IMAP) */
60 };
61
62 typedef struct {
63   FILE *fp;                     /* pointer to the message data */
64   char *path;                   /* path to temp file */
65   short magic;                  /* type of mailbox this message belongs to */
66   short write;                  /* nonzero if message is open for writing */
67   struct {
68     unsigned read:1;
69     unsigned flagged:1;
70     unsigned replied:1;
71   } flags;
72   time_t received;              /* the time at which this message was received */
73 } MESSAGE;
74
75 WHERE short DefaultMagic INITVAL (M_MBOX);
76
77 CONTEXT *mx_open_mailbox (const char *, int, CONTEXT *);
78
79 MESSAGE *mx_open_message (CONTEXT *, int);
80 MESSAGE *mx_open_new_message (CONTEXT *, HEADER *, int);
81
82 void mx_fastclose_mailbox (CONTEXT *);
83
84 int mx_close_mailbox (CONTEXT *, int *);
85 int mx_sync_mailbox (CONTEXT *, int *);
86 int mx_commit_message (MESSAGE *, CONTEXT *);
87 int mx_close_message (MESSAGE **);
88 int mx_get_magic (const char *);
89 int mx_set_magic (const char *);
90 int mx_check_mailbox (CONTEXT *, int *, int);
91
92 #ifdef USE_IMAP
93 int mx_is_imap (const char *);
94 #endif
95 #ifdef USE_POP
96 int mx_is_pop (const char *);
97 #endif
98 #ifdef USE_NNTP
99 int mx_is_nntp (const char *);
100 #endif
101
102 int mx_access (const char *, int);
103 int mx_check_empty (const char *);
104
105 void mx_alloc_memory (CONTEXT *);
106 void mx_update_context (CONTEXT *, int);
107 void mx_update_tables (CONTEXT *, int);
108
109 int mx_lock_file (const char *, int, int, int, int);
110 int mx_unlock_file (const char *path, int fd, int dot);
111
112 #endif /* !_MX_H */