Commit 3f5059d8 3f5059d80eca4eace1d79a9f41c4d2ea75b8f551 by Alain Magloire

mailbox.c mailbox.h mailboxi.c mbx_imap.c mbx_mbox.c

 	mbx_mdir.c mbx_mmdf.c mbx_pop.c mbx_unix.c

introduce an implementation of mbx_unix
1 parent 1918e4dd
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by 5 it under the terms of the GNU Library General Public License as published by
...@@ -24,57 +24,44 @@ mailbox_open (mailbox_t mbox, int flag) ...@@ -24,57 +24,44 @@ mailbox_open (mailbox_t mbox, int flag)
24 } 24 }
25 25
26 int 26 int
27 mailbox_close (mailbox_t mbox, int flag) 27 mailbox_close (mailbox_t mbox)
28 { 28 {
29 return mbox->_close (mbox, flag); 29 return mbox->_close (mbox);
30 }
31
32
33 /* type */
34 int
35 mailbox_get_type (mailbox_t mbox, int *type, char *desc, int offset, int len)
36 {
37 return mbox->_get_type (mbox, type, desc, offset, len);
38 }
39
40 int
41 mailbox_get_mtype (mailbox_t mbox, int *type, char **desc, int *len)
42 {
43 return mbox->_get_mtype (mbox, type, desc, offset, len);
44 } 30 }
45 31
46 32
47 /* passwd */ 33 /* passwd */
48 int 34 int
49 mailbox_get_passwd (mailbox_t mbox, char *passwd, int offset, int len) 35 mailbox_get_passwd (mailbox_t mbox, char *passwd, size_t len, size_t *n)
50 { 36 {
51 return mbox->_get_passwd (mbox, passwd, offset, len); 37 return mbox->_get_passwd (mbox, passwd, len, n);
52 } 38 }
53 39
54 int 40 int
55 mailbox_get_mpasswd (mailbox_t mbox, char **passwd, int *len) 41 mailbox_get_mpasswd (mailbox_t mbox, char **passwd, size_t *n)
56 { 42 {
57 return mbox->_get_mpasswd (mbox, passwd, len); 43 return mbox->_get_mpasswd (mbox, passwd, n);
58 } 44 }
59 45
60 int 46 int
61 mailbox_set_passwd (mailbox_t mbox, const char *passwd, int offset, int len) 47 mailbox_set_passwd (mailbox_t mbox, const char *passwd,
48 size_t len)
62 { 49 {
63 return mbox->_set_passwd (mbox, passwd, offset, len); 50 return mbox->_set_passwd (mbox, passwd, len);
64 } 51 }
65 52
66 53
67 /* deleting */ 54 /* deleting */
68 int 55 int
69 mailbox_delete (mailbox_t mbox, int id) 56 mailbox_delete (mailbox_t mbox, size_t msgno)
70 { 57 {
71 return mbox->_delete (mbox, id); 58 return mbox->_delete (mbox, msgno);
72 } 59 }
73 60
74 int 61 int
75 mailbox_undelete (mailbox_t mbox, int id) 62 mailbox_undelete (mailbox_t mbox, size_t msgno)
76 { 63 {
77 return mbox->_undelete (mbox, id); 64 return mbox->_undelete (mbox, msgno);
78 } 65 }
79 66
80 int 67 int
...@@ -84,69 +71,73 @@ mailbox_expunge (mailbox_t mbox) ...@@ -84,69 +71,73 @@ mailbox_expunge (mailbox_t mbox)
84 } 71 }
85 72
86 int 73 int
87 mailbox_is_deleted (mailbox_t mbox, int) 74 mailbox_is_deleted (mailbox_t mbox, size_t msgno)
88 { 75 {
89 return mbox->_is_deleted (mbox, int); 76 return mbox->_is_deleted (mbox, msgno);
90 } 77 }
91 78
92 79
93 /* appending */ 80 /* appending */
94 int 81 int
95 mailbox_new_msg (mailbox_t mbox, int * id) 82 mailbox_new_msg (mailbox_t mbox, size_t *msgno)
96 { 83 {
97 return mbox->_new_msg (mbox, id); 84 return mbox->_new_msg (mbox, msgno);
98 } 85 }
99 86
100 int 87 int
101 mailbox_set_header (mailbox_t mbox, int id, const char *h, 88 mailbox_set_header (mailbox_t mbox, size_t msgno, const char *h,
102 int offset, int n, int replace) 89 size_t len, int replace)
103 { 90 {
104 return mbox->_set_header (mbox, id, h, offset, n, replace); 91 return mbox->_set_header (mbox, msgno, h, len, replace);
105 } 92 }
106 93
107 int 94 int
108 mailbox_set_body (mailbox_t mbox, int id, const char *b, 95 mailbox_set_body (mailbox_t mbox, size_t msgno, const char *b,
109 int offset, int n, int replace) 96 size_t len, int replace)
110 { 97 {
111 return mbox->_set_body (mbox, id, b, offset, n, replace); 98 return mbox->_set_body (mbox, msgno, b, len, replace);
112 } 99 }
113 100
114 int 101 int
115 mailbox_append (mailbox_t mbox, int id) 102 mailbox_append (mailbox_t mbox, size_t msgno)
116 { 103 {
117 return mbox->_append (mbox, id); 104 return mbox->_append (mbox, msgno);
118 } 105 }
119 106
120 int 107 int
121 mailbox_destroy_msg (mailbox_t mbox, int id) 108 mailbox_destroy_msg (mailbox_t mbox, size_t msgno)
122 { 109 {
123 return mbox->_destroy_msg (mbox, id); 110 return mbox->_destroy_msg (mbox, msgno);
124 } 111 }
125 112
126 113
127 /* reading */ 114 /* reading */
128 int 115 int
129 mailbox_get_body (mailbox_t mbox, int id, char *b, int offset, int n) 116 mailbox_get_body (mailbox_t mbox, size_t msgno, off_t off, char *b,
117 size_t len, size_t *n)
130 { 118 {
131 return mbox->_get_body (mbox, id, b, offset, n); 119 return mbox->_get_body (mbox, msgno, off, b, len, n);
132 } 120 }
133 121
134 int 122 int
135 mailbox_get_mbody (mailbox_t mbox, int id, char **b, int *n) 123 mailbox_get_mbody (mailbox_t mbox, size_t msgno, off_t off,
124 char **b, size_t *n)
136 { 125 {
137 return mbox->_get_body (mbox, id, b, n); 126 return mbox->_get_mbody (mbox, msgno, off, b, n);
138 } 127 }
139 128
140 int 129 int
141 mailbox_get_header (mailbox_t mbox, int id, char *h, int offset, int n) 130 mailbox_get_header (mailbox_t mbox, size_t msgno, off_t off, char *h,
131 size_t len, size_t *n)
142 { 132 {
143 return mbox->_get_header (mbox, id, h, offset, n); 133 return mbox->_get_header (mbox, msgno, off, h, len, n);
144 } 134 }
145 135
146 int 136 int
147 mailbox_get_mheader (mailbox_t mbox, int id, char **h, int *n) 137 mailbox_get_mheader (mailbox_t mbox, size_t msgno, off_t off,
138 char **h, size_t *n)
148 { 139 {
149 return mbox->_get_header (mbox, id, h, n); 140 return mbox->_get_mheader (mbox, msgno, off, h, n);
150 } 141 }
151 142
152 143
...@@ -166,7 +157,7 @@ mailbox_unlock (mailbox_t mbox) ...@@ -166,7 +157,7 @@ mailbox_unlock (mailbox_t mbox)
166 157
167 /* misc */ 158 /* misc */
168 int 159 int
169 mailbox_scan (mailbox_t mbox, int *msgs) 160 mailbox_scan (mailbox_t mbox, size_t *msgs)
170 { 161 {
171 return mbox->_scan (mbox, msgs); 162 return mbox->_scan (mbox, msgs);
172 } 163 }
...@@ -178,31 +169,32 @@ mailbox_is_updated (mailbox_t mbox) ...@@ -178,31 +169,32 @@ mailbox_is_updated (mailbox_t mbox)
178 } 169 }
179 170
180 int 171 int
181 mailbox_get_timeout (mailbox_t mbox, int *timeout) 172 mailbox_get_timeout (mailbox_t mbox, size_t *timeout)
182 { 173 {
183 return mbox->_get_timeout (mbox, timeout); 174 return mbox->_get_timeout (mbox, timeout);
184 } 175 }
185 176
186 int 177 int
187 mailbox_set_timeout (mailbox_t mbox, int timeout) 178 mailbox_set_timeout (mailbox_t mbox, size_t timeout)
188 { 179 {
189 return mbox->_set_timeout (mbox, timeout); 180 return mbox->_set_timeout (mbox, timeout);
190 } 181 }
191 182
192 int 183 int
193 mailbox_get_refresh (mailbox_t mbox, int *refresh) 184 mailbox_get_refresh (mailbox_t mbox, size_t *refresh)
194 { 185 {
195 return mbox->_get_refresh (mbox, refresh); 186 return mbox->_get_refresh (mbox, refresh);
196 } 187 }
197 188
198 int 189 int
199 mailbox_set_refresh (mailbox_t mbox, int refresh) 190 mailbox_set_refresh (mailbox_t mbox, size_t refresh)
200 { 191 {
201 return mbox->_set_refresh (mbox, refresh); 192 return mbox->_set_refresh (mbox, refresh);
202 } 193 }
203 194
204 int 195 int
205 mailbox_set_notification (mailbox_t mbox, int (*notif) __P ((mailbox_t mbox))) 196 mailbox_set_notification (mailbox_t mbox,
197 int (*notif) __P ((mailbox_t, void *)))
206 { 198 {
207 return mbox->_set_notification (mbox, notif); 199 return mbox->_set_notification (mbox, notif);
208 } 200 }
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by 5 it under the terms of the GNU Library General Public License as published by
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 17
18 #include <mbx_imap.h> 18 #include <mbx_imap.h>
19 #include <url_imap.h> 19 #include <url_imap.h>
20 #include <errno.h>
20 21
21 22
22 struct mailbox_type _mailbox_imap_type = 23 struct mailbox_type _mailbox_imap_type =
...@@ -35,5 +36,5 @@ mailbox_imap_destroy (mailbox_t *mbox) ...@@ -35,5 +36,5 @@ mailbox_imap_destroy (mailbox_t *mbox)
35 int 36 int
36 mailbox_imap_init (mailbox_t *mbox, const char *name) 37 mailbox_imap_init (mailbox_t *mbox, const char *name)
37 { 38 {
38 return -1; 39 return ENOSYS;
39 } 40 }
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Library General Public License as published by 5 it under the terms of the GNU Library General Public License as published by
...@@ -59,7 +59,7 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name) ...@@ -59,7 +59,7 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name)
59 */ 59 */
60 if (stat (name, &st) == -1) 60 if (stat (name, &st) == -1)
61 { 61 {
62 return -1; /* errno set by stat () */ 62 return errno; /* errno set by stat () */
63 } 63 }
64 64
65 if (S_ISREG (st.st_mode)) 65 if (S_ISREG (st.st_mode))
...@@ -77,7 +77,7 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name) ...@@ -77,7 +77,7 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name)
77 if (fd == -1) 77 if (fd == -1)
78 { 78 {
79 /* Oops !! wrong permission ? file deleted ? */ 79 /* Oops !! wrong permission ? file deleted ? */
80 return -1; /* errno set by open () */ 80 return errno; /* errno set by open () */
81 } 81 }
82 82
83 /* Read a small chunck */ 83 /* Read a small chunck */
...@@ -91,6 +91,7 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name) ...@@ -91,6 +91,7 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name)
91 */ 91 */
92 if (count == 0) /*empty file*/ 92 if (count == 0) /*empty file*/
93 { 93 {
94 close (fd);
94 return mailbox_unix_init (mbox, name); 95 return mailbox_unix_init (mbox, name);
95 } 96 }
96 97
...@@ -99,11 +100,13 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name) ...@@ -99,11 +100,13 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name)
99 if (strncmp (head, "From ", 5) == 0) 100 if (strncmp (head, "From ", 5) == 0)
100 { 101 {
101 /* This is Unix Mbox */ 102 /* This is Unix Mbox */
103 close (fd);
102 return mailbox_unix_init (mbox, name); 104 return mailbox_unix_init (mbox, name);
103 } 105 }
104 } 106 }
105 107
106 /* Try MMDF */ 108 /* Try MMDF */
109 close (fd);
107 #endif 110 #endif
108 return mailbox_unix_init (mbox, name); 111 return mailbox_unix_init (mbox, name);
109 } 112 }
...@@ -121,5 +124,5 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name) ...@@ -121,5 +124,5 @@ mailbox_mbox_init (mailbox_t *mbox, const char *name)
121 void 124 void
122 mailbox_mbox_destroy (mailbox_t *mbox) 125 mailbox_mbox_destroy (mailbox_t *mbox)
123 { 126 {
124 return (*mbox)->mtype->_destroy (mbox); 127 (*mbox)->mtype->_destroy (mbox);
125 } 128 }
......
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
1 #include <url_mdir.h> 18 #include <url_mdir.h>
2 #include <mbx_mdir.h> 19 #include <mbx_mdir.h>
20 #include <errno.h>
3 21
4 struct mailbox_type _mailbox_maildir_type = 22 struct mailbox_type _mailbox_maildir_type =
5 { 23 {
...@@ -11,7 +29,7 @@ struct mailbox_type _mailbox_maildir_type = ...@@ -11,7 +29,7 @@ struct mailbox_type _mailbox_maildir_type =
11 int 29 int
12 mailbox_maildir_init (mailbox_t *mbox, const char *name) 30 mailbox_maildir_init (mailbox_t *mbox, const char *name)
13 { 31 {
14 return -1; 32 return ENOSYS;
15 } 33 }
16 34
17 void 35 void
......
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
1 #include <url_mmdf.h> 18 #include <url_mmdf.h>
2 #include <mbx_mmdf.h> 19 #include <mbx_mmdf.h>
20 #include <errno.h>
3 21
4 struct mailbox_type _mailbox_maildir_type = 22 struct mailbox_type _mailbox_mmdf_type =
5 { 23 {
6 "MMDF", 24 "MMDF",
7 (int)&_url_mmdf_type, &_url_mmdf_type, 25 (int)&_url_mmdf_type, &_url_mmdf_type,
...@@ -11,7 +29,7 @@ struct mailbox_type _mailbox_maildir_type = ...@@ -11,7 +29,7 @@ struct mailbox_type _mailbox_maildir_type =
11 int 29 int
12 mailbox_mmdf_init (mailbox_t *mbox, const char *name) 30 mailbox_mmdf_init (mailbox_t *mbox, const char *name)
13 { 31 {
14 return -1; 32 return ENOSYS;
15 } 33 }
16 34
17 void 35 void
......
1 /* GNU mailutils - a suite of utilities for electronic mail 1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
3 3
4 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Library Public License as published by 5 it under the terms of the GNU General Library Public License as published by
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
17 17
18 #include <url_pop.h> 18 #include <url_pop.h>
19 #include <mbx_pop.h> 19 #include <mbx_pop.h>
20 #include <errno.h>
20 21
21 struct mailbox_type _mailbox_pop_type = 22 struct mailbox_type _mailbox_pop_type =
22 { 23 {
...@@ -34,5 +35,5 @@ mailbox_pop_destroy (mailbox_t *mbox) ...@@ -34,5 +35,5 @@ mailbox_pop_destroy (mailbox_t *mbox)
34 int 35 int
35 mailbox_pop_init (mailbox_t *mbox, const char *name) 36 mailbox_pop_init (mailbox_t *mbox, const char *name)
36 { 37 {
37 return -1; 38 return ENOSYS;
38 } 39 }
......