Commit 8b262f17 8b262f172f15fb5afa3cb73b7c619650ee5d556f by Alain Magloire

* configure.in: AC_REPLACE_FUNCS(fgetpwent);

	* include/mailutils/parse822.h: Add a prototype for
	parse822_skip_nl().

	* lib/Makefile.am: add fgetpwent.c
	* lib/fgetpwent.c: New file.

	* mail/from.c (mail_from): Use the cover functions
	attribute_is_xxxx() instead of getting the flag.

	* mailbox/attribute.c: Cleanup the mess.
	attribute_set_{read,delete,seen,flagged,answered}.
	attribute_unset_{read,delete,seen,flagged,answered}.
	attribute_is_{read,delete,seen,flagged,answered}
	should be no more then cover functions calling
	attribute_set_flags(), attribute_get_flags() and
	attribute_unset_flags().

	* mailbox/folder_imap.c: MU_ATTRIBUTE_READ, is not
	part of IMAP protocol use \\Seen.
	* mailbox/mbx_imap.c: Remove the hack trying to reconnect,
	it does not work.

	* mailbox/mbx_pop.c(pop_get_messages): Set the new
	functions for the attribute.
	(pop_get_attribute): New functions.
	(pop_set_attribute): New functions.
	(pop_unset_attribute): New functions.
	(pop_attr_flags): Removed.

	* mutil.c (mu_hex2ul): GNU coding std.
	(parse822_time): Do not use tzname as a variable name tzname
	is global variable in libc, better clear away.
	(parse822_date_time): Likewised.

	* pop3d/Makefile.am: add virtual.c
	* pop3d/pop3d.c (main): register getpwnam_ip_virtual,
	getpwnam_host_virtual
	* pop3d/pop3d.h: declare,
	getpwnam_ip_virtual(), getpwnam_host_virtual().
	* pop3d/virtual.c: New file.
1 parent 7191f1db
1 2001-09-03 Alain Magloire
2
3 * configure.in: AC_REPLACE_FUNCS(fgetpwent);
4
5 * include/mailutils/parse822.h: Add a prototype for
6 parse822_skip_nl().
7
8 * lib/Makefile.am: add fgetpwent.c
9 * lib/fgetpwent.c: New file.
10
11 * mail/from.c (mail_from): Use the cover functions
12 attribute_is_xxxx() instead of getting the flag.
13
14 * mailbox/attribute.c: Cleanup the mess.
15 attribute_set_{read,delete,seen,flagged,answered}.
16 attribute_unset_{read,delete,seen,flagged,answered}.
17 attribute_is_{read,delete,seen,flagged,answered}
18 should be no more then cover functions calling
19 attribute_set_flags(), attribute_get_flags() and
20 attribute_unset_flags().
21
22 * mailbox/folder_imap.c: MU_ATTRIBUTE_READ, is not
23 part of IMAP protocol use \\Seen.
24 * mailbox/mbx_imap.c: Remove the hack trying to reconnect,
25 it does not work.
26
27 * mailbox/mbx_pop.c(pop_get_messages): Set the new
28 functions for the attribute.
29 (pop_get_attribute): New functions.
30 (pop_set_attribute): New functions.
31 (pop_unset_attribute): New functions.
32 (pop_attr_flags): Removed.
33
34 * mutil.c (mu_hex2ul): GNU coding std.
35 (parse822_time): Do not use tzname as a variable name tzname
36 is global variable in libc, better clear away.
37 (parse822_date_time): Likewised.
38
39 * pop3d/Makefile.am: add virtual.c
40 * pop3d/pop3d.c (main): register getpwnam_ip_virtual,
41 getpwnam_host_virtual
42 * pop3d/pop3d.h: declare,
43 getpwnam_ip_virtual(), getpwnam_host_virtual().
44 * pop3d/virtual.c: New file.
45
1 2001-09-02 Alain Magloire 46 2001-09-02 Alain Magloire
2 47
3 * mailbox/mutil.c (getpwma_virtual): Memory overrun, did not 48 * mailbox/mutil.c (getpwma_virtual): Memory overrun, did not
......
...@@ -113,8 +113,8 @@ AC_FUNC_FNMATCH ...@@ -113,8 +113,8 @@ AC_FUNC_FNMATCH
113 if test "$ac_cv_func_fnmatch_works" = "no"; then 113 if test "$ac_cv_func_fnmatch_works" = "no"; then
114 : LIBOBJS="$LIBOBJS fnmatch.o" 114 : LIBOBJS="$LIBOBJS fnmatch.o"
115 fi 115 fi
116 AC_REPLACE_FUNCS(setenv snprintf strtok_r strncasecmp strcasecmp strsignal \ 116 AC_REPLACE_FUNCS(fgetpwent setenv snprintf strtok_r strncasecmp strcasecmp \
117 vasprintf) 117 strsignal vasprintf)
118 AC_CHECK_FUNCS(mkstemp sigaction sysconf) 118 AC_CHECK_FUNCS(mkstemp sigaction sysconf)
119 119
120 dnl Check for libraries 120 dnl Check for libraries
......
...@@ -60,6 +60,7 @@ extern int parse822_skip_crlf __P ((const char** p, const char* e)); ...@@ -60,6 +60,7 @@ extern int parse822_skip_crlf __P ((const char** p, const char* e));
60 extern int parse822_skip_lwsp_char __P ((const char** p, const char* e)); 60 extern int parse822_skip_lwsp_char __P ((const char** p, const char* e));
61 extern int parse822_skip_lwsp __P ((const char** p, const char* e)); 61 extern int parse822_skip_lwsp __P ((const char** p, const char* e));
62 extern int parse822_skip_comments __P ((const char** p, const char* e)); 62 extern int parse822_skip_comments __P ((const char** p, const char* e));
63 extern int parse822_skip_nl __P ((const char** p, const char* e));
63 64
64 extern int parse822_digits __P ((const char** p, const char* e, int min, int max, int* digits)); 65 extern int parse822_digits __P ((const char** p, const char* e, int min, int max, int* digits));
65 extern int parse822_special __P ((const char** p, const char* e, char c)); 66 extern int parse822_special __P ((const char** p, const char* e, char c));
...@@ -104,7 +105,7 @@ extern int parse822_field_name __P ((const char** p, const char *e, char** ...@@ -104,7 +105,7 @@ extern int parse822_field_name __P ((const char** p, const char *e, char**
104 105
105 extern int parse822_day __P ((const char** p, const char* e, int* day)); 106 extern int parse822_day __P ((const char** p, const char* e, int* day));
106 extern int parse822_date __P ((const char** p, const char* e, int* day, int* mon, int* year)); 107 extern int parse822_date __P ((const char** p, const char* e, int* day, int* mon, int* year));
107 extern int parse822_time __P ((const char** p, const char* e, int* h, int* m, int* s, int* tz, const char** tzname)); 108 extern int parse822_time __P ((const char** p, const char* e, int* h, int* m, int* s, int* tz, const char** tz_name));
108 extern int parse822_date_time __P ((const char** p, const char* e, struct tm* tm, mu_timezone* tz)); 109 extern int parse822_date_time __P ((const char** p, const char* e, struct tm* tm, mu_timezone* tz));
109 110
110 111
......
...@@ -7,7 +7,8 @@ libmailutils_a_SOURCES = basename.c getopt.c getopt1.c md5.c getline.c \ ...@@ -7,7 +7,8 @@ libmailutils_a_SOURCES = basename.c getopt.c getopt1.c md5.c getline.c \
7 xstrdup.c xmalloc.c argcv.c 7 xstrdup.c xmalloc.c argcv.c
8 8
9 EXTRA_DIST = alloca.c fnmatch.c setenv.c snprintf.c strchrnul.c strndup.c \ 9 EXTRA_DIST = alloca.c fnmatch.c setenv.c snprintf.c strchrnul.c strndup.c \
10 strnlen.c strtok_r.c strsignal.c xstrtol.c vasprintf.c malloc.c realloc.c 10 strnlen.c strtok_r.c strsignal.c xstrtol.c vasprintf.c malloc.c realloc.c \
11 fgetpwent.c
11 12
12 noinst_HEADERS = argcv.h error.h fnmatch.h getline.h getopt.h md5.h \ 13 noinst_HEADERS = argcv.h error.h fnmatch.h getline.h getopt.h md5.h \
13 regex.h snprintf.h xalloc.h xstrtol.h 14 regex.h snprintf.h xalloc.h xstrtol.h
......
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22 #include <stdio.h>
23 #include <pwd.h>
24 #include <string.h>
25 #include <stdlib.h>
26
27 /*
28 Written by Alain Magloire.
29 Simple replacement for fgetpwent(), it is not :
30 - thread safe;
31 - static buffer was not use since it will limit the size
32 of the entry. But rather memory is allocated and __never__
33 release. The memory will grow if need be.
34 - no support for shadow
35 - no support for NIS(+)
36 */
37
38 static char *buffer;
39 static size_t buflen;
40 static struct passwd pw;
41
42
43 static char *
44 parse_line (char *s, char **p)
45 {
46 if (*s)
47 {
48 char *sep = strchr (s, ':');
49 if (sep)
50 {
51 *sep++ = '\0';
52 *p = sep;
53 }
54 else
55 *p = s + strlen (s);
56 }
57 else
58 *p = s;
59 return s;
60 }
61
62 static struct passwd *
63 getentry (char *s)
64 {
65 char *p;
66 pw.pw_name = parse_line (s, &p);
67 s = p;
68 pw.pw_passwd = parse_line (s, &p);
69 s = p;
70 pw.pw_uid = strtoul (parse_line (s, &p), NULL, 10);
71 s = p;
72 pw.pw_gid = strtoul (parse_line (s, &p), NULL, 10);
73 s = p;
74 pw.pw_gecos = parse_line (s, &p);
75 s = p;
76 pw.pw_dir = parse_line (s, &p);
77 s = p;
78 pw.pw_shell = parse_line (s, &p);
79 return &pw;
80 }
81
82 struct passwd *
83 fgetpwent (FILE *fp)
84 {
85 size_t pos = 0;
86 int done = 0;
87 struct passwd *pw = NULL;
88
89 /* Allocate buffer if not yet available. */
90 /* This buffer will be never free(). */
91 if (buffer == NULL)
92 {
93 buflen = 1024;
94 buffer = malloc (buflen);
95 if (buffer == NULL)
96 return NULL;
97 }
98
99 do
100 {
101 if (fgets (buffer + pos, buflen, fp) != NULL)
102 {
103 /* Need a full line. */
104 if (buffer[strlen (buffer) - 1] == '\n')
105 {
106 /* reset marker position. */
107 pos = 0;
108 /* Nuke trailing newline. */
109 buffer[strlen (buffer) - 1] = '\0';
110
111 /* Skip comments. */
112 if (buffer[0] != '#')
113 {
114 done = 1;
115 pw = getentry (buffer);
116 }
117 }
118 else
119 {
120 /* Line is too long reallocate the buffer. */
121 char *tmp;
122 pos = strlen (buffer);
123 buflen *= 2;
124 tmp = realloc (buffer, buflen);
125 if (tmp)
126 buffer = tmp;
127 else
128 done = 1;
129 }
130 }
131 else
132 done = 1;
133 } while (!done);
134
135 return pw;
136
137 }
138
139 #ifdef STANDALONE
140 int
141 main ()
142 {
143 FILE *fp = fopen ("/etc/passwd", "r");
144 if (fp)
145 {
146 struct passwd *pwd;
147 while ((pwd = fgetpwent (fp)))
148 {
149 printf ("--------------------------------------\n");
150 printf ("name %s\n", pwd->pw_name);
151 printf ("passwd %s\n", pwd->pw_passwd);
152 printf ("uid %d\n", pwd->pw_uid);
153 printf ("gid %d\n", pwd->pw_gid);
154 printf ("gecos %s\n", pwd->pw_gecos);
155 printf ("dir %s\n", pwd->pw_dir);
156 printf ("shell %s\n", pwd->pw_shell);
157 }
158 }
159 return 0;
160 }
161
162 #endif
...@@ -36,7 +36,7 @@ mail_from (int argc, char **argv) ...@@ -36,7 +36,7 @@ mail_from (int argc, char **argv)
36 int froml, subjl; 36 int froml, subjl;
37 char date[80], st[10]; 37 char date[80], st[10];
38 int cols = util_getcols () - 6; 38 int cols = util_getcols () - 6;
39 int flags, cflag; 39 int cflag;
40 size_t m_size = 0, m_lines = 0; 40 size_t m_size = 0, m_lines = 0;
41 const char *p; 41 const char *p;
42 struct tm tm; 42 struct tm tm;
...@@ -78,7 +78,6 @@ mail_from (int argc, char **argv) ...@@ -78,7 +78,6 @@ mail_from (int argc, char **argv)
78 } 78 }
79 79
80 message_get_attribute (msg, &attr); 80 message_get_attribute (msg, &attr);
81 attribute_get_flags (attr, &flags);
82 81
83 if (attribute_is_userflag(attr, MAIL_ATTRIBUTE_MBOXED)) 82 if (attribute_is_userflag(attr, MAIL_ATTRIBUTE_MBOXED))
84 cflag = 'M'; 83 cflag = 'M';
...@@ -86,9 +85,9 @@ mail_from (int argc, char **argv) ...@@ -86,9 +85,9 @@ mail_from (int argc, char **argv)
86 cflag = '*'; 85 cflag = '*';
87 else if (attribute_is_userflag(attr, MAIL_ATTRIBUTE_TAGGED)) 86 else if (attribute_is_userflag(attr, MAIL_ATTRIBUTE_TAGGED))
88 cflag = 'T'; 87 cflag = 'T';
89 else if (flags & MU_ATTRIBUTE_READ) 88 else if (attribute_is_read (attr))
90 cflag = 'R'; 89 cflag = 'R';
91 else if (flags & MU_ATTRIBUTE_SEEN) 90 else if (attribute_is_seen (attr))
92 cflag = 'U'; 91 cflag = 'U';
93 else if (attribute_is_recent(attr)) 92 else if (attribute_is_recent(attr))
94 cflag = 'N'; 93 cflag = 'N';
......
...@@ -42,5 +42,3 @@ mail_mbox (int argc, char **argv) ...@@ -42,5 +42,3 @@ mail_mbox (int argc, char **argv)
42 } 42 }
43 return 0; 43 return 0;
44 } 44 }
45
46
......
...@@ -100,5 +100,3 @@ mail_print (int argc, char **argv) ...@@ -100,5 +100,3 @@ mail_print (int argc, char **argv)
100 } 100 }
101 return 1; 101 return 1;
102 } 102 }
103
104
......
...@@ -47,4 +47,3 @@ mail_tag (int argc, char **argv) ...@@ -47,4 +47,3 @@ mail_tag (int argc, char **argv)
47 msgset_free (msgset); 47 msgset_free (msgset);
48 return 0; 48 return 0;
49 } 49 }
50
......
...@@ -53,7 +53,7 @@ attribute_destroy (attribute_t *pattr, void *owner) ...@@ -53,7 +53,7 @@ attribute_destroy (attribute_t *pattr, void *owner)
53 attribute_t attr = *pattr; 53 attribute_t attr = *pattr;
54 if (attr->owner == owner) 54 if (attr->owner == owner)
55 free (*pattr); 55 free (*pattr);
56 /* loose the link */ 56 /* Loose the link */
57 *pattr = NULL; 57 *pattr = NULL;
58 } 58 }
59 } 59 }
...@@ -74,9 +74,6 @@ int ...@@ -74,9 +74,6 @@ int
74 attribute_clear_modified (attribute_t attr) 74 attribute_clear_modified (attribute_t attr)
75 { 75 {
76 if (!attr) 76 if (!attr)
77 return 0;
78 if (attr->_unset_flags)
79 attr->_unset_flags (attr, MU_ATTRIBUTE_MODIFIED);
80 attr->flags &= ~MU_ATTRIBUTE_MODIFIED; 77 attr->flags &= ~MU_ATTRIBUTE_MODIFIED;
81 return 0; 78 return 0;
82 } 79 }
...@@ -84,23 +81,18 @@ attribute_clear_modified (attribute_t attr) ...@@ -84,23 +81,18 @@ attribute_clear_modified (attribute_t attr)
84 int 81 int
85 attribute_set_modified (attribute_t attr) 82 attribute_set_modified (attribute_t attr)
86 { 83 {
87 int status;
88 if (!attr) 84 if (!attr)
89 return EINVAL;
90 if (attr->_set_flags)
91 status = attr->_set_flags (attr, MU_ATTRIBUTE_MODIFIED);
92 attr->flags |= MU_ATTRIBUTE_MODIFIED; 85 attr->flags |= MU_ATTRIBUTE_MODIFIED;
93 return status; 86 return 0;
94 } 87 }
95 88
96 int 89 int
97 attribute_get_flags (attribute_t attr, int *pflags) 90 attribute_get_flags (attribute_t attr, int *pflags)
98 { 91 {
99 if (attr == NULL) 92 if (attr == NULL || pflags == NULL)
100 return EINVAL; 93 return EINVAL;
101 if (attr->_get_flags) 94 if (attr->_get_flags)
102 return attr->_get_flags (attr, pflags); 95 return attr->_get_flags (attr, pflags);
103 if (pflags)
104 *pflags = attr->flags; 96 *pflags = attr->flags;
105 return 0; 97 return 0;
106 } 98 }
...@@ -108,22 +100,30 @@ attribute_get_flags (attribute_t attr, int *pflags) ...@@ -108,22 +100,30 @@ attribute_get_flags (attribute_t attr, int *pflags)
108 int 100 int
109 attribute_set_flags (attribute_t attr, int flags) 101 attribute_set_flags (attribute_t attr, int flags)
110 { 102 {
103 int status = 0;
111 if (attr == NULL) 104 if (attr == NULL)
112 return EINVAL; 105 return EINVAL;
113 if (attr->_set_flags) 106 if (attr->_set_flags)
114 attr->_set_flags (attr, flags); 107 status = attr->_set_flags (attr, flags);
108 else
115 attr->flags |= flags; 109 attr->flags |= flags;
110 if (status == 0)
111 attribute_set_modified (attr);
116 return 0; 112 return 0;
117 } 113 }
118 114
119 int 115 int
120 attribute_unset_flags (attribute_t attr, int flags) 116 attribute_unset_flags (attribute_t attr, int flags)
121 { 117 {
118 int status = 0;
122 if (attr == NULL) 119 if (attr == NULL)
123 return EINVAL; 120 return EINVAL;
124 if (attr->_unset_flags) 121 if (attr->_unset_flags)
125 attr->_unset_flags (attr, flags); 122 status = attr->_unset_flags (attr, flags);
123 else
126 attr->flags &= ~flags; 124 attr->flags &= ~flags;
125 if (status == 0)
126 attribute_set_modified (attr);
127 return 0; 127 return 0;
128 } 128 }
129 129
...@@ -177,91 +177,45 @@ attribute_set_userflag (attribute_t attr, int flag) ...@@ -177,91 +177,45 @@ attribute_set_userflag (attribute_t attr, int flag)
177 int 177 int
178 attribute_set_seen (attribute_t attr) 178 attribute_set_seen (attribute_t attr)
179 { 179 {
180 int status = 0; 180 return attribute_set_flags (attr, MU_ATTRIBUTE_SEEN);
181 if (attr == NULL)
182 return EINVAL;
183 if (attr->_set_flags)
184 status = attr->_set_flags (attr, MU_ATTRIBUTE_SEEN | MU_ATTRIBUTE_MODIFIED);
185 attr->flags |= MU_ATTRIBUTE_SEEN | MU_ATTRIBUTE_MODIFIED;
186 return status;
187 } 181 }
188 182
189 int 183 int
190 attribute_set_answered (attribute_t attr) 184 attribute_set_answered (attribute_t attr)
191 { 185 {
192 int status = 0; 186 return attribute_set_flags (attr, MU_ATTRIBUTE_ANSWERED);
193 if (attr == NULL)
194 return EINVAL;
195 if (attr->_set_flags)
196 status = attr->_set_flags (attr, MU_ATTRIBUTE_ANSWERED | MU_ATTRIBUTE_MODIFIED);
197 attr->flags |= MU_ATTRIBUTE_ANSWERED | MU_ATTRIBUTE_MODIFIED;
198 return status;
199 } 187 }
200 188
201 int 189 int
202 attribute_set_flagged (attribute_t attr) 190 attribute_set_flagged (attribute_t attr)
203 { 191 {
204 int status = 0; 192 return attribute_set_flags (attr, MU_ATTRIBUTE_FLAGGED);
205 if (attr == NULL)
206 return EINVAL;
207 if (attr->_set_flags)
208 status = attr->_set_flags (attr, MU_ATTRIBUTE_FLAGGED | MU_ATTRIBUTE_MODIFIED);
209 attr->flags |= MU_ATTRIBUTE_FLAGGED | MU_ATTRIBUTE_MODIFIED;
210 return status;
211 } 193 }
212 194
213 int 195 int
214 attribute_set_read (attribute_t attr) 196 attribute_set_read (attribute_t attr)
215 { 197 {
216 int status = 0; 198 return attribute_set_flags (attr, MU_ATTRIBUTE_READ);
217 if (attr == NULL)
218 return EINVAL;
219 if (attr->_set_flags)
220 status = attr->_set_flags (attr, MU_ATTRIBUTE_READ | MU_ATTRIBUTE_MODIFIED);
221 attr->flags |= MU_ATTRIBUTE_READ | MU_ATTRIBUTE_MODIFIED;
222 return status;
223 } 199 }
224 200
225 int 201 int
226 attribute_set_deleted (attribute_t attr) 202 attribute_set_deleted (attribute_t attr)
227 { 203 {
228 int status = 0; 204 return attribute_set_flags (attr, MU_ATTRIBUTE_DELETED);
229 if (attr == NULL)
230 return EINVAL;
231 if (attr->_set_flags)
232 status = attr->_set_flags (attr, MU_ATTRIBUTE_DELETED | MU_ATTRIBUTE_MODIFIED);
233 attr->flags |= MU_ATTRIBUTE_DELETED | MU_ATTRIBUTE_MODIFIED;
234 return 0;
235 } 205 }
236 206
237 int 207 int
238 attribute_set_draft (attribute_t attr) 208 attribute_set_draft (attribute_t attr)
239 { 209 {
240 int status = 0; 210 return attribute_set_flags (attr, MU_ATTRIBUTE_DRAFT);
241 if (attr == NULL)
242 return EINVAL;
243 if (attr->_set_flags)
244 status = attr->_set_flags (attr, MU_ATTRIBUTE_DRAFT | MU_ATTRIBUTE_MODIFIED);
245 attr->flags |= MU_ATTRIBUTE_DRAFT | MU_ATTRIBUTE_MODIFIED;
246 return status;
247 } 211 }
248 212
249 int 213 int
250 attribute_set_recent (attribute_t attr) 214 attribute_set_recent (attribute_t attr)
251 { 215 {
252 int status = 0; 216 int status = attribute_unset_flags (attr, MU_ATTRIBUTE_READ);
253 if (attr == NULL) 217 if (status == 0)
254 return EINVAL; 218 status = attribute_unset_flags (attr, MU_ATTRIBUTE_SEEN);
255 if (attr->_unset_flags)
256 {
257 status |= attr->_unset_flags (attr, MU_ATTRIBUTE_READ);
258 status |= attr->_unset_flags (attr, MU_ATTRIBUTE_SEEN);
259 }
260 if (attr == NULL)
261 {
262 attr->flags &= ~MU_ATTRIBUTE_READ;
263 attr->flags &= ~MU_ATTRIBUTE_SEEN;
264 }
265 return status; 219 return status;
266 } 220 }
267 221
...@@ -276,74 +230,68 @@ attribute_is_userflag (attribute_t attr, int flag) ...@@ -276,74 +230,68 @@ attribute_is_userflag (attribute_t attr, int flag)
276 int 230 int
277 attribute_is_seen (attribute_t attr) 231 attribute_is_seen (attribute_t attr)
278 { 232 {
279 if (attr == NULL) 233 int flags = 0;
234 if (attribute_get_flags (attr, &flags) == 0)
235 return flags & MU_ATTRIBUTE_SEEN;
280 return 0; 236 return 0;
281 if (attr->_get_flags)
282 attr->_get_flags (attr, &(attr->flags));
283 return attr->flags & MU_ATTRIBUTE_SEEN;
284 } 237 }
285 238
286 int 239 int
287 attribute_is_answered (attribute_t attr) 240 attribute_is_answered (attribute_t attr)
288 { 241 {
289 if (attr == NULL) 242 int flags = 0;
243 if (attribute_get_flags (attr, &flags) == 0)
244 return flags & MU_ATTRIBUTE_ANSWERED;
290 return 0; 245 return 0;
291 if (attr->_get_flags)
292 attr->_get_flags (attr, &(attr->flags));
293 return attr->flags & MU_ATTRIBUTE_ANSWERED;
294 } 246 }
295 247
296 int 248 int
297 attribute_is_flagged (attribute_t attr) 249 attribute_is_flagged (attribute_t attr)
298 { 250 {
299 if (attr == NULL) 251 int flags = 0;
252 if (attribute_get_flags (attr, &flags) == 0)
253 return flags & MU_ATTRIBUTE_FLAGGED;
300 return 0; 254 return 0;
301 if (attr->_get_flags)
302 attr->_get_flags (attr, &(attr->flags));
303 return attr->flags & MU_ATTRIBUTE_FLAGGED;
304 } 255 }
305 256
306 int 257 int
307 attribute_is_read (attribute_t attr) 258 attribute_is_read (attribute_t attr)
308 { 259 {
309 if (attr == NULL) 260 int flags = 0;
261 if (attribute_get_flags (attr, &flags) == 0)
262 return flags & MU_ATTRIBUTE_READ;
310 return 0; 263 return 0;
311 if (attr->_get_flags)
312 attr->_get_flags (attr, &(attr->flags));
313 return attr->flags & MU_ATTRIBUTE_READ;
314 } 264 }
315 265
316 int 266 int
317 attribute_is_deleted (attribute_t attr) 267 attribute_is_deleted (attribute_t attr)
318 { 268 {
319 if (attr == NULL) 269 int flags = 0;
270 if (attribute_get_flags (attr, &flags) == 0)
271 return flags & MU_ATTRIBUTE_DELETED;
320 return 0; 272 return 0;
321 if (attr->_get_flags)
322 attr->_get_flags (attr, &(attr->flags));
323 return attr->flags & MU_ATTRIBUTE_DELETED;
324 } 273 }
325 274
326 int 275 int
327 attribute_is_draft (attribute_t attr) 276 attribute_is_draft (attribute_t attr)
328 { 277 {
329 if (attr == NULL) 278 int flags = 0;
279 if (attribute_get_flags (attr, &flags) == 0)
280 return flags & MU_ATTRIBUTE_DRAFT;
330 return 0; 281 return 0;
331 if (attr->_get_flags)
332 attr->_get_flags (attr, &(attr->flags));
333 return attr->flags & MU_ATTRIBUTE_DRAFT;
334 } 282 }
335 283
336 int 284 int
337 attribute_is_recent (attribute_t attr) 285 attribute_is_recent (attribute_t attr)
338 { 286 {
339 if (attr == NULL) 287 int flags = 0;
340 return 0; 288 if (attribute_get_flags (attr, &flags) == 0)
341 if (attr->_get_flags) 289 {
342 attr->_get_flags (attr, &(attr->flags));
343 /* something is recent when it is not read and not seen. */ 290 /* something is recent when it is not read and not seen. */
344 return (attr->flags == 0 291 return (flags == 0 || ! ((flags & MU_ATTRIBUTE_SEEN)
345 || ! ((attr->flags & MU_ATTRIBUTE_SEEN) 292 || (flags & MU_ATTRIBUTE_READ)));
346 || (attr->flags & MU_ATTRIBUTE_READ))); 293 }
294 return 0;
347 } 295 }
348 296
349 int 297 int
...@@ -358,105 +306,52 @@ attribute_unset_userflag (attribute_t attr, int flag) ...@@ -358,105 +306,52 @@ attribute_unset_userflag (attribute_t attr, int flag)
358 int 306 int
359 attribute_unset_seen (attribute_t attr) 307 attribute_unset_seen (attribute_t attr)
360 { 308 {
361 int status = 0; 309 return attribute_unset_flags (attr, MU_ATTRIBUTE_SEEN);
362 if (attr == NULL)
363 return 0;
364 if (attr->_unset_flags)
365 status = attr->_unset_flags (attr, MU_ATTRIBUTE_SEEN);
366 attr->flags &= ~MU_ATTRIBUTE_SEEN;
367 attribute_set_modified (attr);
368 return status;
369 } 310 }
370 311
371 int 312 int
372 attribute_unset_answered (attribute_t attr) 313 attribute_unset_answered (attribute_t attr)
373 { 314 {
374 int status = 0; 315 return attribute_unset_flags (attr, MU_ATTRIBUTE_ANSWERED);
375 if (attr == NULL)
376 return 0;
377 if (attr->_unset_flags)
378 status = attr->_unset_flags (attr, MU_ATTRIBUTE_ANSWERED);
379 attr->flags &= ~MU_ATTRIBUTE_ANSWERED;
380 attribute_set_modified (attr);
381 return status;
382 } 316 }
383 317
384 int 318 int
385 attribute_unset_flagged (attribute_t attr) 319 attribute_unset_flagged (attribute_t attr)
386 { 320 {
387 int status = 0; 321 return attribute_unset_flags (attr, MU_ATTRIBUTE_FLAGGED);
388 if (attr == NULL)
389 return 0;
390 if (attr->_unset_flags)
391 status = attr->_unset_flags (attr, MU_ATTRIBUTE_FLAGGED);
392 attr->flags &= ~MU_ATTRIBUTE_FLAGGED;
393 attribute_set_modified (attr);
394 return status;
395 } 322 }
396 323
397 int 324 int
398 attribute_unset_read (attribute_t attr) 325 attribute_unset_read (attribute_t attr)
399 { 326 {
400 int status = 0; 327 return attribute_unset_flags (attr, MU_ATTRIBUTE_READ);
401 if (attr == NULL)
402 return 0;
403 if (attr->_unset_flags)
404 status = attr->_unset_flags (attr, MU_ATTRIBUTE_READ);
405 attr->flags &= ~MU_ATTRIBUTE_READ;
406 attribute_set_modified (attr);
407 return status;
408 } 328 }
409 329
410 int 330 int
411 attribute_unset_deleted (attribute_t attr) 331 attribute_unset_deleted (attribute_t attr)
412 { 332 {
413 int status = 0; 333 return attribute_unset_flags (attr, MU_ATTRIBUTE_DELETED);
414 if (attr == NULL)
415 return 0;
416 if (attr->_unset_flags)
417 status = attr->_unset_flags (attr, MU_ATTRIBUTE_DELETED);
418 attr->flags &= ~MU_ATTRIBUTE_DELETED;
419 attribute_set_modified (attr);
420 return status;
421 } 334 }
422 335
423 int 336 int
424 attribute_unset_draft (attribute_t attr) 337 attribute_unset_draft (attribute_t attr)
425 { 338 {
426 int status = 0; 339 return attribute_unset_flags (attr, MU_ATTRIBUTE_DRAFT);
427 if (attr == NULL)
428 return 0;
429 if (attr->_unset_flags)
430 status = attr->_unset_flags (attr, MU_ATTRIBUTE_DRAFT);
431 attr->flags &= ~MU_ATTRIBUTE_DRAFT;
432 attribute_set_modified (attr);
433 return status;
434 } 340 }
435 341
436 int 342 int
437 attribute_unset_recent (attribute_t attr) 343 attribute_unset_recent (attribute_t attr)
438 { 344 {
439 int status = 0; 345 return attribute_unset_flags (attr, MU_ATTRIBUTE_SEEN);
440 if (attr == NULL)
441 return 0;
442 if (attr->_unset_flags)
443 status = attr->_unset_flags (attr, MU_ATTRIBUTE_SEEN);
444 attr->flags |= MU_ATTRIBUTE_SEEN;
445 attribute_set_modified (attr);
446 return status;
447 } 346 }
448 347
449 int 348 int
450 attribute_is_equal (attribute_t attr, attribute_t attr2) 349 attribute_is_equal (attribute_t attr, attribute_t attr2)
451 { 350 {
452 int status = 0; 351 int flags2 = 0, flags = 0;
453 if (attr == NULL || attr2 == NULL) 352 attribute_get_flags (attr, &flags);
454 return 0; 353 attribute_get_flags (attr2, &flags2);
455 if (attr->_get_flags) 354 return flags == flags;
456 status = attr->_get_flags (attr, &(attr->flags));
457 if (attr2->_get_flags)
458 status = attr2->_get_flags (attr2, &(attr2->flags));
459 return attr->flags == attr2->flags;
460 } 355 }
461 356
462 /* Miscellaneous. */ 357 /* Miscellaneous. */
...@@ -550,3 +445,4 @@ flags_to_string (int flags, char *buffer, size_t len, size_t *pn) ...@@ -550,3 +445,4 @@ flags_to_string (int flags, char *buffer, size_t len, size_t *pn)
550 *pn = i; 445 *pn = i;
551 return 0; 446 return 0;
552 } 447 }
448
......
...@@ -1262,7 +1262,10 @@ imap_flags (f_imap_t f_imap, char **ptr) ...@@ -1262,7 +1262,10 @@ imap_flags (f_imap_t f_imap, char **ptr)
1262 if (strcasecmp (flag, "\\Seen") == 0) 1262 if (strcasecmp (flag, "\\Seen") == 0)
1263 { 1263 {
1264 if (msg_imap) 1264 if (msg_imap)
1265 {
1265 msg_imap->flags |= MU_ATTRIBUTE_SEEN; 1266 msg_imap->flags |= MU_ATTRIBUTE_SEEN;
1267 msg_imap->flags |= MU_ATTRIBUTE_READ;
1268 }
1266 else 1269 else
1267 f_imap->flags |= MU_ATTRIBUTE_SEEN; 1270 f_imap->flags |= MU_ATTRIBUTE_SEEN;
1268 } 1271 }
...@@ -1294,13 +1297,6 @@ imap_flags (f_imap_t f_imap, char **ptr) ...@@ -1294,13 +1297,6 @@ imap_flags (f_imap_t f_imap, char **ptr)
1294 else 1297 else
1295 f_imap->flags |= MU_ATTRIBUTE_DRAFT; 1298 f_imap->flags |= MU_ATTRIBUTE_DRAFT;
1296 } 1299 }
1297 else if (strcasecmp (flag, "\\Read") == 0)
1298 {
1299 if (msg_imap)
1300 msg_imap->flags |= MU_ATTRIBUTE_READ;
1301 else
1302 f_imap->flags |= MU_ATTRIBUTE_READ;
1303 }
1304 } 1300 }
1305 return 0; 1301 return 0;
1306 } 1302 }
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
31 #endif 31 #endif
32 32
33 #include <mailutils/mailbox.h> 33 #include <mailutils/mailbox.h>
34 #include <mailutils/mutil.h>
34 #include <mailutils/error.h> 35 #include <mailutils/error.h>
35 36
36 #ifndef _PATH_MAILDIR 37 #ifndef _PATH_MAILDIR
......
...@@ -500,18 +500,7 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum) ...@@ -500,18 +500,7 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum)
500 500
501 case IMAP_SELECT: 501 case IMAP_SELECT:
502 status = imap_send (f_imap); 502 status = imap_send (f_imap);
503 if (status != 0)
504 {
505 /* HACK!!!!! Force a reconnect here. */
506 if (status != EAGAIN && status != EINPROGRESS && status != EINTR)
507 {
508 CLEAR_STATE (f_imap);
509 status = folder_open (f_imap->folder, f_imap->folder->flags);
510 CHECK_EAGAIN (f_imap, status); 503 CHECK_EAGAIN (f_imap, status);
511 return imap_messages_count (mailbox, pnum);
512 }
513 return status;
514 }
515 f_imap->state = IMAP_SELECT_ACK; 504 f_imap->state = IMAP_SELECT_ACK;
516 505
517 case IMAP_SELECT_ACK: 506 case IMAP_SELECT_ACK:
...@@ -521,7 +510,6 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum) ...@@ -521,7 +510,6 @@ imap_messages_count (mailbox_t mailbox, size_t *pnum)
521 break; 510 break;
522 511
523 default: 512 default:
524 status = folder_open (f_imap->folder, f_imap->folder->flags);
525 CHECK_EAGAIN (f_imap, status); 513 CHECK_EAGAIN (f_imap, status);
526 return status; 514 return status;
527 } 515 }
......
...@@ -111,7 +111,9 @@ static int pop_message_fd __P ((stream_t, int *)); ...@@ -111,7 +111,9 @@ static int pop_message_fd __P ((stream_t, int *));
111 static int pop_top __P ((header_t, char *, size_t, off_t, size_t *)); 111 static int pop_top __P ((header_t, char *, size_t, off_t, size_t *));
112 static int pop_retr __P ((pop_message_t, char *, size_t, off_t, size_t *)); 112 static int pop_retr __P ((pop_message_t, char *, size_t, off_t, size_t *));
113 static int pop_get_fd __P ((pop_message_t, int *)); 113 static int pop_get_fd __P ((pop_message_t, int *));
114 static int pop_attr_flags __P ((attribute_t, int *)); 114 static int pop_get_attribute __P ((attribute_t, int *));
115 static int pop_set_attribute __P ((attribute_t, int));
116 static int pop_unset_attribute __P ((attribute_t, int));
115 static int pop_uidl __P ((message_t, char *, size_t, size_t *)); 117 static int pop_uidl __P ((message_t, char *, size_t, size_t *));
116 static int pop_uid __P ((message_t, size_t *)); 118 static int pop_uid __P ((message_t, size_t *));
117 static int fill_buffer __P ((pop_data_t, char *, size_t)); 119 static int fill_buffer __P ((pop_data_t, char *, size_t));
...@@ -140,6 +142,7 @@ struct _pop_message ...@@ -140,6 +142,7 @@ struct _pop_message
140 size_t message_size; 142 size_t message_size;
141 size_t num; 143 size_t num;
142 char *uidl; /* Cache the uidl string. */ 144 char *uidl; /* Cache the uidl string. */
145 int attr_flags;
143 message_t message; 146 message_t message;
144 pop_data_t mpd; /* Back pointer. */ 147 pop_data_t mpd; /* Back pointer. */
145 }; 148 };
...@@ -809,7 +812,9 @@ pop_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg) ...@@ -809,7 +812,9 @@ pop_get_message (mailbox_t mbox, size_t msgno, message_t *pmsg)
809 free (mpm); 812 free (mpm);
810 return status; 813 return status;
811 } 814 }
812 attribute_set_get_flags (attribute, pop_attr_flags, msg); 815 attribute_set_get_flags (attribute, pop_get_attribute, msg);
816 attribute_set_set_flags (attribute, pop_set_attribute, msg);
817 attribute_set_unset_flags (attribute, pop_unset_attribute, msg);
813 message_set_attribute (msg, attribute, mpm); 818 message_set_attribute (msg, attribute, mpm);
814 } 819 }
815 820
...@@ -1214,19 +1219,47 @@ pop_body_lines (body_t body, size_t *plines) ...@@ -1214,19 +1219,47 @@ pop_body_lines (body_t body, size_t *plines)
1214 the RETR some go as much as deleting after the TOP, since technicaly 1219 the RETR some go as much as deleting after the TOP, since technicaly
1215 you can download a message via TOP without RET'reiving it. */ 1220 you can download a message via TOP without RET'reiving it. */
1216 static int 1221 static int
1217 pop_attr_flags (attribute_t attr, int *pflags) 1222 pop_get_attribute (attribute_t attr, int *pflags)
1218 { 1223 {
1219 message_t msg = attribute_get_owner (attr); 1224 message_t msg = attribute_get_owner (attr);
1220 pop_message_t mpm = message_get_owner (msg); 1225 pop_message_t mpm = message_get_owner (msg);
1221 char hdr_status[64]; 1226 char hdr_status[64];
1222 header_t header = NULL; 1227 header_t header = NULL;
1223 1228
1224 if (mpm == NULL) 1229 if (mpm == NULL || pflags == NULL)
1225 return EINVAL; 1230 return EINVAL;
1231 if (mpm->attr_flags == 0)
1232 {
1226 hdr_status[0] = '\0'; 1233 hdr_status[0] = '\0';
1227 message_get_header (mpm->message, &header); 1234 message_get_header (mpm->message, &header);
1228 header_get_value (header, "Status", hdr_status, sizeof (hdr_status), NULL); 1235 header_get_value (header, "Status", hdr_status, sizeof hdr_status, NULL);
1229 string_to_flags (hdr_status, pflags); 1236 string_to_flags (hdr_status, &(mpm->attr_flags));
1237 }
1238 *pflags = mpm->attr_flags;
1239 return 0;
1240 }
1241
1242 static int
1243 pop_set_attribute (attribute_t attr, int flags)
1244 {
1245 message_t msg = attribute_get_owner (attr);
1246 pop_message_t mpm = message_get_owner (msg);
1247
1248 if (mpm == NULL)
1249 return EINVAL;
1250 mpm->attr_flags |= flags;
1251 return 0;
1252 }
1253
1254 static int
1255 pop_unset_attribute (attribute_t attr, int flags)
1256 {
1257 message_t msg = attribute_get_owner (attr);
1258 pop_message_t mpm = message_get_owner (msg);
1259
1260 if (mpm == NULL)
1261 return EINVAL;
1262 mpm->attr_flags &= ~flags;
1230 return 0; 1263 return 0;
1231 } 1264 }
1232 1265
......
...@@ -35,7 +35,8 @@ ...@@ -35,7 +35,8 @@
35 35
36 /* convert a sequence of hex characters into an integer */ 36 /* convert a sequence of hex characters into an integer */
37 37
38 unsigned long mu_hex2ul(char hex) 38 unsigned long
39 mu_hex2ul (char hex)
39 { 40 {
40 if (hex >= '0' && hex <= '9') 41 if (hex >= '0' && hex <= '9')
41 return hex - '0'; 42 return hex - '0';
...@@ -49,7 +50,8 @@ unsigned long mu_hex2ul(char hex) ...@@ -49,7 +50,8 @@ unsigned long mu_hex2ul(char hex)
49 return -1; 50 return -1;
50 } 51 }
51 52
52 size_t mu_hexstr2ul(unsigned long* ul, const char* hex, size_t len) 53 size_t
54 mu_hexstr2ul (unsigned long *ul, const char *hex, size_t len)
53 { 55 {
54 size_t r; 56 size_t r;
55 57
...@@ -57,9 +59,9 @@ size_t mu_hexstr2ul(unsigned long* ul, const char* hex, size_t len) ...@@ -57,9 +59,9 @@ size_t mu_hexstr2ul(unsigned long* ul, const char* hex, size_t len)
57 59
58 for (r = 0; r < len; r++) 60 for (r = 0; r < len; r++)
59 { 61 {
60 unsigned long v = mu_hex2ul(hex[r]); 62 unsigned long v = mu_hex2ul (hex[r]);
61 63
62 if(v == (unsigned long)-1) 64 if (v == (unsigned long)-1)
63 return r; 65 return r;
64 66
65 *ul = *ul * 16 + v; 67 *ul = *ul * 16 + v;
...@@ -83,18 +85,18 @@ mu_tm2time (struct tm *timeptr, mu_timezone* tz) ...@@ -83,18 +85,18 @@ mu_tm2time (struct tm *timeptr, mu_timezone* tz)
83 { 85 {
84 int offset = tz ? tz->utc_offset : 0; 86 int offset = tz ? tz->utc_offset : 0;
85 87
86 return mktime(timeptr) + mu_utc_offset() - offset; 88 return mktime (timeptr) + mu_utc_offset () - offset;
87 } 89 }
88 90
89 /* Convert time 0 at UTC to our localtime, that tells us the offset 91 /* Convert time 0 at UTC to our localtime, that tells us the offset
90 of our current timezone from UTC. */ 92 of our current timezone from UTC. */
91 time_t 93 time_t
92 mu_utc_offset(void) 94 mu_utc_offset (void)
93 { 95 {
94 time_t t = 0; 96 time_t t = 0;
95 struct tm* tm = gmtime(&t); 97 struct tm* tm = gmtime (&t);
96 98
97 return - mktime(tm); 99 return - mktime (tm);
98 } 100 }
99 101
100 static const char *months[] = 102 static const char *months[] =
...@@ -243,7 +245,6 @@ mu_parse_ctime_date_time (const char **p, struct tm *tm, mu_timezone * tz) ...@@ -243,7 +245,6 @@ mu_parse_ctime_date_time (const char **p, struct tm *tm, mu_timezone * tz)
243 return 0; 245 return 0;
244 } 246 }
245 247
246
247 char * 248 char *
248 mu_get_homedir (void) 249 mu_get_homedir (void)
249 { 250 {
...@@ -252,7 +253,7 @@ mu_get_homedir (void) ...@@ -252,7 +253,7 @@ mu_get_homedir (void)
252 { 253 {
253 struct passwd *pwd; 254 struct passwd *pwd;
254 255
255 pwd = getpwuid(getuid()); 256 pwd = getpwuid (getuid ());
256 if (!pwd) 257 if (!pwd)
257 return NULL; 258 return NULL;
258 homedir = pwd->pw_dir; 259 homedir = pwd->pw_dir;
...@@ -369,7 +370,7 @@ getpwnam_virtual (const char *u) ...@@ -369,7 +370,7 @@ getpwnam_virtual (const char *u)
369 { 370 {
370 struct passwd *pw = NULL; 371 struct passwd *pw = NULL;
371 FILE *pfile; 372 FILE *pfile;
372 int i = 0, len = strlen (u), delim = 0; 373 size_t i = 0, len = strlen (u), delim = 0;
373 char *filename; 374 char *filename;
374 375
375 mu_virtual_domain = 0; 376 mu_virtual_domain = 0;
......
...@@ -1292,7 +1292,7 @@ int parse822_date(const char** p, const char* e, int* day, int* mon, int* year) ...@@ -1292,7 +1292,7 @@ int parse822_date(const char** p, const char* e, int* day, int* mon, int* year)
1292 } 1292 }
1293 1293
1294 int parse822_time(const char** p, const char* e, 1294 int parse822_time(const char** p, const char* e,
1295 int* hour, int* min, int* sec, int* tz, const char** tzname) 1295 int* hour, int* min, int* sec, int* tz, const char** tz_name)
1296 { 1296 {
1297 /* time = hour zone 1297 /* time = hour zone
1298 * hour = 2DIGIT ":" 2DIGIT [":" 2DIGIT] ; 00:00:00 - 23:59:59 1298 * hour = 2DIGIT ":" 2DIGIT [":" 2DIGIT] ; 00:00:00 - 23:59:59
...@@ -1323,7 +1323,7 @@ int parse822_time(const char** p, const char* e, ...@@ -1323,7 +1323,7 @@ int parse822_time(const char** p, const char* e,
1323 { "MDT", -6 * 60 * 60 }, 1323 { "MDT", -6 * 60 * 60 },
1324 { "PST", -8 * 60 * 60 }, 1324 { "PST", -8 * 60 * 60 },
1325 { "PDT", -7 * 60 * 60 }, 1325 { "PDT", -7 * 60 * 60 },
1326 { NULL, } 1326 { NULL, 0 }
1327 }; 1327 };
1328 1328
1329 const char* save = *p; 1329 const char* save = *p;
...@@ -1370,8 +1370,8 @@ int parse822_time(const char** p, const char* e, ...@@ -1370,8 +1370,8 @@ int parse822_time(const char** p, const char* e,
1370 break; 1370 break;
1371 } 1371 }
1372 if(tzs[z].tzname) { 1372 if(tzs[z].tzname) {
1373 if(tzname) 1373 if(tz_name)
1374 *tzname = tzs[z].tzname; 1374 *tz_name = tzs[z].tzname;
1375 1375
1376 if(tz) 1376 if(tz)
1377 *tz = tzs[z].tz; 1377 *tz = tzs[z].tz;
...@@ -1449,7 +1449,7 @@ int parse822_date_time(const char** p, const char* e, struct tm* tm, struct mu_t ...@@ -1449,7 +1449,7 @@ int parse822_date_time(const char** p, const char* e, struct tm* tm, struct mu_t
1449 int sec = 0; 1449 int sec = 0;
1450 1450
1451 int tzoffset = 0; 1451 int tzoffset = 0;
1452 const char* tzname = 0; 1452 const char* tz_name = 0;
1453 1453
1454 if((rc = parse822_day(p, e, &wday))) { 1454 if((rc = parse822_day(p, e, &wday))) {
1455 if(rc != EPARSE) 1455 if(rc != EPARSE)
...@@ -1468,7 +1468,7 @@ int parse822_date_time(const char** p, const char* e, struct tm* tm, struct mu_t ...@@ -1468,7 +1468,7 @@ int parse822_date_time(const char** p, const char* e, struct tm* tm, struct mu_t
1468 *p = save; 1468 *p = save;
1469 return rc; 1469 return rc;
1470 } 1470 }
1471 if((rc = parse822_time(p, e, &hour, &min, &sec, &tzoffset, &tzname))) { 1471 if((rc = parse822_time(p, e, &hour, &min, &sec, &tzoffset, &tz_name))) {
1472 *p = save; 1472 *p = save;
1473 return rc; 1473 return rc;
1474 } 1474 }
...@@ -1493,14 +1493,14 @@ int parse822_date_time(const char** p, const char* e, struct tm* tm, struct mu_t ...@@ -1493,14 +1493,14 @@ int parse822_date_time(const char** p, const char* e, struct tm* tm, struct mu_t
1493 tm->tm_gmtoff = tzoffset; 1493 tm->tm_gmtoff = tzoffset;
1494 #endif 1494 #endif
1495 #ifdef HAVE_TM_ZONE 1495 #ifdef HAVE_TM_ZONE
1496 tm->tm_zone = tzname; 1496 tm->tm_zone = tz_name;
1497 #endif 1497 #endif
1498 } 1498 }
1499 1499
1500 if(tz) 1500 if(tz)
1501 { 1501 {
1502 tz->utc_offset = tzoffset; 1502 tz->utc_offset = tzoffset;
1503 tz->tz_name = tzname; 1503 tz->tz_name = tz_name;
1504 } 1504 }
1505 1505
1506 return EOK; 1506 return EOK;
......
...@@ -143,7 +143,7 @@ url_parse (url_t url) ...@@ -143,7 +143,7 @@ url_parse (url_t url)
143 { 143 {
144 int err = 0; 144 int err = 0;
145 char *n = NULL; 145 char *n = NULL;
146 struct _url u = { 0, }; 146 struct _url u = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0 ,0, 0};
147 147
148 if (!url || !url->name) 148 if (!url || !url->name)
149 return EINVAL; 149 return EINVAL;
......
...@@ -4,6 +4,7 @@ INCLUDES =-I$(srcdir) -I$(top_srcdir)/lib -I$(top_srcdir)/include ...@@ -4,6 +4,7 @@ INCLUDES =-I$(srcdir) -I$(top_srcdir)/lib -I$(top_srcdir)/include
4 sbin_PROGRAMS = pop3d 4 sbin_PROGRAMS = pop3d
5 5
6 pop3d_SOURCES = apop.c auth.c capa.c dele.c extra.c pop3d.c pop3d.h \ 6 pop3d_SOURCES = apop.c auth.c capa.c dele.c extra.c pop3d.c pop3d.h \
7 list.c lock.c noop.c quit.c retr.c rset.c stat.c top.c uidl.c user.c signal.c 7 list.c lock.c noop.c quit.c retr.c rset.c stat.c signal.c top.c uidl.c \
8 user.c virtual.c
8 9
9 pop3d_LDADD = ../mailbox/libmailbox.la @AUTHLIBS@ ../lib/libmailutils.a 10 pop3d_LDADD = ../mailbox/libmailbox.la @AUTHLIBS@ ../lib/libmailutils.a
......
...@@ -134,6 +134,8 @@ main (int argc, char **argv) ...@@ -134,6 +134,8 @@ main (int argc, char **argv)
134 #endif 134 #endif
135 #ifdef USE_VIRTUAL_DOMAINS 135 #ifdef USE_VIRTUAL_DOMAINS
136 mu_register_getpwnam (getpwnam_virtual); 136 mu_register_getpwnam (getpwnam_virtual);
137 mu_register_getpwnam (getpwnam_ip_virtual);
138 mu_register_getpwnam (getpwnam_host_virtual);
137 #endif 139 #endif
138 140
139 /* Set the signal handlers. */ 141 /* Set the signal handlers. */
......
...@@ -201,4 +201,7 @@ extern int pop3d_touchlock __P ((void)); ...@@ -201,4 +201,7 @@ extern int pop3d_touchlock __P ((void));
201 extern int pop3d_uidl __P ((const char *)); 201 extern int pop3d_uidl __P ((const char *));
202 extern int pop3d_user __P ((const char *)); 202 extern int pop3d_user __P ((const char *));
203 extern int pop3d_unlock __P ((void)); 203 extern int pop3d_unlock __P ((void));
204
205 extern struct passwd * getpwnam_ip_virtual __P ((const char *u));
206 extern struct passwd * getpwnam_host_virtual __P ((const char *u));
204 #endif /* _POP3D_H */ 207 #endif /* _POP3D_H */
......
1 /* GNU mailutils - a suite of utilities for electronic mail
2 Copyright (C) 1999, 2000, 2001 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 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 General Public License for more details.
13
14 You should have received a copy of the GNU 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
18
19 #include "pop3d.h"
20
21 #ifdef USE_VIRTUAL_DOMAINS
22
23 struct passwd *
24 getpwnam_ip_virtual (const char *u)
25 {
26 struct sockaddr_in addr;
27 struct passwd *pw = NULL;
28 int len = sizeof (addr);
29 if (getsockname (fileno (ifile), (struct sockaddr *)&addr, &len) == 0)
30 {
31 char *ip;
32 char *user;
33 ip = inet_ntoa (addr.sin_addr);
34 user = malloc (strlen (ip) + strlen (u) + 2);
35 if (user)
36 {
37 sprintf (user, "%s!%s", u, ip);
38 pw = getpwnam_virtual (user);
39 free (user);
40 }
41 }
42 return pw;
43 }
44
45 struct passwd *
46 getpwnam_host_virtual (const char *u)
47 {
48 struct sockaddr_in addr;
49 struct passwd *pw = NULL;
50 int len = sizeof (addr);
51 if (getsockname (fileno (ifile), (struct sockaddr *)&addr, &len) == 0)
52 {
53 struct hostent *info = gethostbyaddr ((char *)&addr.sin_addr,
54 4, AF_INET);
55 if (info)
56 {
57 char *user = malloc (strlen (info->h_name) + strlen (u) + 2);
58 if (user)
59 {
60 sprintf (user, "%s!%s", u, info->h_name);
61 pw = getpwnam_virtual (user);
62 free (user);
63 }
64 }
65 }
66 return pw;
67 }
68
69 #endif