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
...@@ -243,7 +243,7 @@ fi ...@@ -243,7 +243,7 @@ fi
243 243
244 dnl Output Makefiles 244 dnl Output Makefiles
245 AC_OUTPUT(Makefile mailutils.spec include/Makefile include/mailutils/Makefile 245 AC_OUTPUT(Makefile mailutils.spec include/Makefile include/mailutils/Makefile
246 m4/Makefile doc/Makefile argp/Makefile lib/Makefile lib/posix/Makefile 246 m4/Makefile doc/Makefile argp/Makefile lib/Makefile lib/posix/Makefile
247 mailbox/Makefile imap4d/Makefile mailbox/include/Makefile from/Makefile 247 mailbox/Makefile imap4d/Makefile mailbox/include/Makefile from/Makefile
248 mail/Makefile pop3d/Makefile frm/Makefile sieve/Makefile messages/Makefile 248 mail/Makefile pop3d/Makefile frm/Makefile sieve/Makefile messages/Makefile
249 scripts/Makefile libmu_scm/Makefile guimb/Makefile guimb/scm/Makefile MySql/Makefile) 249 scripts/Makefile libmu_scm/Makefile guimb/Makefile guimb/scm/Makefile MySql/Makefile)
......
...@@ -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
...@@ -37,7 +37,7 @@ mail_copy0 (int argc, char **argv, int mark) ...@@ -37,7 +37,7 @@ mail_copy0 (int argc, char **argv, int mark)
37 msgset_t *msglist = NULL, *mp; 37 msgset_t *msglist = NULL, *mp;
38 int sender = 0; 38 int sender = 0;
39 size_t total_size = 0, total_lines = 0, size; 39 size_t total_size = 0, total_lines = 0, size;
40 40
41 if (isupper (argv[0][0])) 41 if (isupper (argv[0][0]))
42 sender = 1; 42 sender = 1;
43 else if (argc >= 2) 43 else if (argc >= 2)
...@@ -80,9 +80,9 @@ mail_copy0 (int argc, char **argv, int mark) ...@@ -80,9 +80,9 @@ mail_copy0 (int argc, char **argv, int mark)
80 total_size += size; 80 total_size += size;
81 message_lines (msg, &size); 81 message_lines (msg, &size);
82 total_lines += size; 82 total_lines += size;
83 83
84 if (mark) 84 if (mark)
85 { 85 {
86 attribute_t attr; 86 attribute_t attr;
87 message_get_attribute (msg, &attr); 87 message_get_attribute (msg, &attr);
88 attribute_set_userflag (attr, MAIL_ATTRIBUTE_SAVED); 88 attribute_set_userflag (attr, MAIL_ATTRIBUTE_SAVED);
......
...@@ -40,7 +40,7 @@ mail_decode (int argc, char **argv) ...@@ -40,7 +40,7 @@ mail_decode (int argc, char **argv)
40 { 40 {
41 msgset_t *msgset; 41 msgset_t *msgset;
42 struct decode_closure decode_closure; 42 struct decode_closure decode_closure;
43 43
44 if (msgset_parse (argc, argv, &msgset)) 44 if (msgset_parse (argc, argv, &msgset))
45 return 1; 45 return 1;
46 46
...@@ -58,10 +58,10 @@ display_message (message_t mesg, msgset_t *msgset, ...@@ -58,10 +58,10 @@ display_message (message_t mesg, msgset_t *msgset,
58 { 58 {
59 FILE *out; 59 FILE *out;
60 size_t lines = 0; 60 size_t lines = 0;
61 61
62 if (util_isdeleted (msgset->msg_part[0])) 62 if (util_isdeleted (msgset->msg_part[0]))
63 return 1; 63 return 1;
64 64
65 message_lines (mesg, &lines); 65 message_lines (mesg, &lines);
66 if ((util_find_env("crt"))->set && lines > util_getlines ()) 66 if ((util_find_env("crt"))->set && lines > util_getlines ())
67 out = popen (getenv("PAGER"), "w"); 67 out = popen (getenv("PAGER"), "w");
...@@ -82,7 +82,7 @@ display_message (message_t mesg, msgset_t *msgset, ...@@ -82,7 +82,7 @@ display_message (message_t mesg, msgset_t *msgset,
82 } 82 }
83 return 0; 83 return 0;
84 } 84 }
85 85
86 static void 86 static void
87 display_headers (FILE *out, message_t mesg, const msgset_t *msgset, 87 display_headers (FILE *out, message_t mesg, const msgset_t *msgset,
88 int select_hdr) 88 int select_hdr)
...@@ -94,7 +94,7 @@ display_headers (FILE *out, message_t mesg, const msgset_t *msgset, ...@@ -94,7 +94,7 @@ display_headers (FILE *out, message_t mesg, const msgset_t *msgset,
94 size_t num = 0; 94 size_t num = 0;
95 size_t i = 0; 95 size_t i = 0;
96 char buffer[512]; 96 char buffer[512];
97 97
98 message_get_header (mesg, &hdr); 98 message_get_header (mesg, &hdr);
99 header_get_field_count (hdr, &num); 99 header_get_field_count (hdr, &num);
100 for (i = 1; i <= num; i++) 100 for (i = 1; i <= num; i++)
...@@ -137,7 +137,7 @@ display_part_header (FILE *out, const msgset_t *msgset, ...@@ -137,7 +137,7 @@ display_part_header (FILE *out, const msgset_t *msgset,
137 for (i = 1; i < msgset->npart; i++) 137 for (i = 1; i < msgset->npart; i++)
138 fprintf (out, "]"); 138 fprintf (out, "]");
139 fprintf (out, "\n"); 139 fprintf (out, "\n");
140 140
141 fprintf (out, "| Type=%s\n", type); 141 fprintf (out, "| Type=%s\n", type);
142 fprintf (out, "| encoding=%s\n", encoding); 142 fprintf (out, "| encoding=%s\n", encoding);
143 fputc ('+', out); 143 fputc ('+', out);
...@@ -156,7 +156,7 @@ display_message0 (FILE *out, message_t mesg, const msgset_t *msgset, ...@@ -156,7 +156,7 @@ display_message0 (FILE *out, message_t mesg, const msgset_t *msgset,
156 char *type; 156 char *type;
157 char *encoding; 157 char *encoding;
158 int ismime = 0; 158 int ismime = 0;
159 159
160 message_get_header (mesg, &hdr); 160 message_get_header (mesg, &hdr);
161 util_get_content_type (hdr, &type); 161 util_get_content_type (hdr, &type);
162 get_content_encoding (hdr, &encoding); 162 get_content_encoding (hdr, &encoding);
...@@ -184,7 +184,7 @@ display_message0 (FILE *out, message_t mesg, const msgset_t *msgset, ...@@ -184,7 +184,7 @@ display_message0 (FILE *out, message_t mesg, const msgset_t *msgset,
184 else if (strncasecmp (type, "message/rfc822", strlen (type)) == 0) 184 else if (strncasecmp (type, "message/rfc822", strlen (type)) == 0)
185 { 185 {
186 message_t submsg = NULL; 186 message_t submsg = NULL;
187 187
188 if (message_unencapsulate (mesg, &submsg, NULL) == 0) 188 if (message_unencapsulate (mesg, &submsg, NULL) == 0)
189 display_message0 (out, submsg, msgset, select_hdr); 189 display_message0 (out, submsg, msgset, select_hdr);
190 } 190 }
...@@ -199,7 +199,7 @@ display_message0 (FILE *out, message_t mesg, const msgset_t *msgset, ...@@ -199,7 +199,7 @@ display_message0 (FILE *out, message_t mesg, const msgset_t *msgset,
199 { 199 {
200 body_t body = NULL; 200 body_t body = NULL;
201 stream_t b_stream = NULL; 201 stream_t b_stream = NULL;
202 202
203 display_part_header (out, msgset, type, encoding); 203 display_part_header (out, msgset, type, encoding);
204 display_headers (out, mesg, msgset, select_hdr); 204 display_headers (out, mesg, msgset, select_hdr);
205 205
...@@ -208,20 +208,20 @@ display_message0 (FILE *out, message_t mesg, const msgset_t *msgset, ...@@ -208,20 +208,20 @@ display_message0 (FILE *out, message_t mesg, const msgset_t *msgset,
208 { 208 {
209 stream_t d_stream = NULL; 209 stream_t d_stream = NULL;
210 stream_t stream = NULL; 210 stream_t stream = NULL;
211 211
212 /* Can we decode. */ 212 /* Can we decode. */
213 if (filter_create(&d_stream, b_stream, encoding, 213 if (filter_create(&d_stream, b_stream, encoding,
214 MU_FILTER_DECODE, MU_STREAM_READ) == 0) 214 MU_FILTER_DECODE, MU_STREAM_READ) == 0)
215 stream = d_stream; 215 stream = d_stream;
216 else 216 else
217 stream = b_stream; 217 stream = b_stream;
218 218
219 print_stream (stream, out); 219 print_stream (stream, out);
220 if (d_stream) 220 if (d_stream)
221 stream_destroy (&d_stream, NULL); 221 stream_destroy (&d_stream, NULL);
222 } 222 }
223 } 223 }
224 224
225 free (type); 225 free (type);
226 free (encoding); 226 free (encoding);
227 227
......
...@@ -50,7 +50,7 @@ mail_delete (int argc, char **argv) ...@@ -50,7 +50,7 @@ mail_delete (int argc, char **argv)
50 { 50 {
51 message_t msg; 51 message_t msg;
52 attribute_t attr; 52 attribute_t attr;
53 53
54 mailbox_get_message (mbox, realcursor, &msg); 54 mailbox_get_message (mbox, realcursor, &msg);
55 message_get_attribute (msg, &attr); 55 message_get_attribute (msg, &attr);
56 if (!attribute_is_deleted (attr)) 56 if (!attribute_is_deleted (attr))
...@@ -59,13 +59,13 @@ mail_delete (int argc, char **argv) ...@@ -59,13 +59,13 @@ mail_delete (int argc, char **argv)
59 realcursor = 1; 59 realcursor = 1;
60 } 60 }
61 while (realcursor != here); 61 while (realcursor != here);
62 62
63 cursor = realcursor; 63 cursor = realcursor;
64 } 64 }
65 65
66 if (util_find_env("autoprint")->set) 66 if (util_find_env("autoprint")->set)
67 util_do_command("print"); 67 util_do_command("print");
68 68
69 return rc; 69 return rc;
70 } 70 }
71 71
......
...@@ -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';
......
...@@ -27,7 +27,7 @@ mail_hold (int argc, char **argv) ...@@ -27,7 +27,7 @@ mail_hold (int argc, char **argv)
27 { 27 {
28 message_t msg; 28 message_t msg;
29 attribute_t attr; 29 attribute_t attr;
30 30
31 if (argc > 1) 31 if (argc > 1)
32 return util_msglist_command (mail_hold, argc, argv, 1); 32 return util_msglist_command (mail_hold, argc, argv, 1);
33 else 33 else
......
...@@ -125,7 +125,7 @@ struct message_set ...@@ -125,7 +125,7 @@ struct message_set
125 int *msg_part; /* Array of part numbers: msg_part[0] is the message 125 int *msg_part; /* Array of part numbers: msg_part[0] is the message
126 number */ 126 number */
127 }; 127 };
128 128
129 /* Global variables and constants*/ 129 /* Global variables and constants*/
130 extern mailbox_t mbox; 130 extern mailbox_t mbox;
131 extern unsigned int cursor; 131 extern unsigned int cursor;
......
...@@ -26,7 +26,7 @@ mail_mbox (int argc, char **argv) ...@@ -26,7 +26,7 @@ mail_mbox (int argc, char **argv)
26 { 26 {
27 message_t msg; 27 message_t msg;
28 attribute_t attr; 28 attribute_t attr;
29 29
30 if (argc > 1) 30 if (argc > 1)
31 return util_msglist_command (mail_mbox, argc, argv, 1); 31 return util_msglist_command (mail_mbox, argc, argv, 1);
32 else 32 else
...@@ -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
......
...@@ -28,7 +28,7 @@ struct header_data ...@@ -28,7 +28,7 @@ struct header_data
28 char *header; 28 char *header;
29 char *expr; 29 char *expr;
30 }; 30 };
31 31
32 static msgset_t *msgset_select (int (*sel)(), void *closure, int rev, 32 static msgset_t *msgset_select (int (*sel)(), void *closure, int rev,
33 int max_matches); 33 int max_matches);
34 static int select_header (message_t msg, void *closure); 34 static int select_header (message_t msg, void *closure);
...@@ -114,7 +114,7 @@ msg : header REGEXP /* /.../ */ ...@@ -114,7 +114,7 @@ msg : header REGEXP /* /.../ */
114 { 114 {
115 struct header_data hd; 115 struct header_data hd;
116 hd.header = $1; 116 hd.header = $1;
117 hd.expr = $2; 117 hd.expr = $2;
118 $$ = msgset_select (select_header, &hd, 0, 0); 118 $$ = msgset_select (select_header, &hd, 0, 0);
119 if ($1) 119 if ($1)
120 free ($1); 120 free ($1);
...@@ -289,7 +289,7 @@ yylex() ...@@ -289,7 +289,7 @@ yylex()
289 { 289 {
290 char *p = ++cur_p; 290 char *p = ++cur_p;
291 int len; 291 int len;
292 292
293 while (*cur_p && *cur_p != '/') 293 while (*cur_p && *cur_p != '/')
294 cur_p++; 294 cur_p++;
295 len = cur_p - p + 1; 295 len = cur_p - p + 1;
...@@ -487,7 +487,7 @@ select_header (message_t msg, void *closure) ...@@ -487,7 +487,7 @@ select_header (message_t msg, void *closure)
487 header_t hdr; 487 header_t hdr;
488 char *contents; 488 char *contents;
489 char *header = hd->header ? hd->header : MU_HEADER_SUBJECT; 489 char *header = hd->header ? hd->header : MU_HEADER_SUBJECT;
490 490
491 message_get_header (msg, &hdr); 491 message_get_header (msg, &hdr);
492 if (header_aget_value (hdr, header, &contents) == 0) 492 if (header_aget_value (hdr, header, &contents) == 0)
493 { 493 {
......
...@@ -40,7 +40,7 @@ mail_print (int argc, char **argv) ...@@ -40,7 +40,7 @@ mail_print (int argc, char **argv)
40 size_t n = 0, lines = 0; 40 size_t n = 0, lines = 0;
41 FILE *out = ofile; 41 FILE *out = ofile;
42 attribute_t attr; 42 attribute_t attr;
43 43
44 if (mailbox_get_message (mbox, cursor, &mesg) != 0) 44 if (mailbox_get_message (mbox, cursor, &mesg) != 0)
45 return 1; 45 return 1;
46 46
...@@ -56,7 +56,7 @@ mail_print (int argc, char **argv) ...@@ -56,7 +56,7 @@ mail_print (int argc, char **argv)
56 { 56 {
57 size_t i, num = 0; 57 size_t i, num = 0;
58 char buffer[512]; 58 char buffer[512];
59 59
60 message_get_header (mesg, &hdr); 60 message_get_header (mesg, &hdr);
61 header_get_field_count (hdr, &num); 61 header_get_field_count (hdr, &num);
62 62
...@@ -95,10 +95,8 @@ mail_print (int argc, char **argv) ...@@ -95,10 +95,8 @@ mail_print (int argc, char **argv)
95 95
96 message_get_attribute (mesg, &attr); 96 message_get_attribute (mesg, &attr);
97 attribute_set_read (attr); 97 attribute_set_read (attr);
98 98
99 return 0; 99 return 0;
100 } 100 }
101 return 1; 101 return 1;
102 } 102 }
103
104
......
...@@ -35,10 +35,10 @@ mail_mbox_close () ...@@ -35,10 +35,10 @@ mail_mbox_close ()
35 { 35 {
36 url_t url = NULL; 36 url_t url = NULL;
37 size_t held_count; 37 size_t held_count;
38 38
39 if (mail_mbox_commit ()) 39 if (mail_mbox_commit ())
40 return 1; 40 return 1;
41 41
42 mailbox_save_attributes (mbox); 42 mailbox_save_attributes (mbox);
43 mailbox_expunge (mbox); 43 mailbox_expunge (mbox);
44 44
...@@ -63,9 +63,9 @@ mail_mbox_commit () ...@@ -63,9 +63,9 @@ mail_mbox_commit ()
63 int hold = util_find_env ("hold")->set; 63 int hold = util_find_env ("hold")->set;
64 url_t url; 64 url_t url;
65 int is_user_mbox; 65 int is_user_mbox;
66 66
67 mailbox_get_url (mbox, &url); 67 mailbox_get_url (mbox, &url);
68 is_user_mbox = strcmp (url_to_string (url), getenv("MBOX")) == 0; 68 is_user_mbox = strcmp (url_to_string (url), getenv("MBOX")) == 0;
69 69
70 { 70 {
71 mailbox_t mb; 71 mailbox_t mb;
...@@ -97,7 +97,7 @@ mail_mbox_commit () ...@@ -97,7 +97,7 @@ mail_mbox_commit ()
97 if (!dest_mbox) 97 if (!dest_mbox)
98 { 98 {
99 char *name = getenv ("MBOX"); 99 char *name = getenv ("MBOX");
100 100
101 if (mailbox_create_default (&dest_mbox, name) 101 if (mailbox_create_default (&dest_mbox, name)
102 || mailbox_open (dest_mbox, 102 || mailbox_open (dest_mbox,
103 MU_STREAM_WRITE | MU_STREAM_CREAT)) 103 MU_STREAM_WRITE | MU_STREAM_CREAT))
...@@ -106,7 +106,7 @@ mail_mbox_commit () ...@@ -106,7 +106,7 @@ mail_mbox_commit ()
106 return 1; 106 return 1;
107 } 107 }
108 } 108 }
109 109
110 mailbox_append_message (dest_mbox, msg); 110 mailbox_append_message (dest_mbox, msg);
111 attribute_set_deleted (attr); 111 attribute_set_deleted (attr);
112 saved_count++; 112 saved_count++;
......
...@@ -38,7 +38,7 @@ mail_tag (int argc, char **argv) ...@@ -38,7 +38,7 @@ mail_tag (int argc, char **argv)
38 { 38 {
39 msgset_t *msgset; 39 msgset_t *msgset;
40 int action = argv[0][0] != 'u'; 40 int action = argv[0][0] != 'u';
41 41
42 if (msgset_parse (argc, argv, &msgset)) 42 if (msgset_parse (argc, argv, &msgset))
43 return 1; 43 return 1;
44 44
...@@ -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
......
...@@ -141,7 +141,7 @@ util_msglist_command (function_t *func, int argc, char **argv, int set_cursor) ...@@ -141,7 +141,7 @@ util_msglist_command (function_t *func, int argc, char **argv, int set_cursor)
141 { 141 {
142 msgset_t *list = NULL, *mp; 142 msgset_t *list = NULL, *mp;
143 int status = 0; 143 int status = 0;
144 144
145 if (msgset_parse (argc, argv, &list)) 145 if (msgset_parse (argc, argv, &list))
146 return 1; 146 return 1;
147 147
...@@ -840,7 +840,7 @@ util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part) ...@@ -840,7 +840,7 @@ util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part)
840 int nparts = 0; 840 int nparts = 0;
841 char *type = NULL; 841 char *type = NULL;
842 header_t hdr = NULL; 842 header_t hdr = NULL;
843 843
844 message_get_header (mesg, &hdr); 844 message_get_header (mesg, &hdr);
845 util_get_content_type (hdr, &type); 845 util_get_content_type (hdr, &type);
846 if (strncasecmp (type, "message/rfc822", strlen (type)) == 0) 846 if (strncasecmp (type, "message/rfc822", strlen (type)) == 0)
...@@ -852,7 +852,7 @@ util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part) ...@@ -852,7 +852,7 @@ util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part)
852 } 852 }
853 mesg = submsg; 853 mesg = submsg;
854 } 854 }
855 855
856 message_get_num_parts (mesg, &nparts); 856 message_get_num_parts (mesg, &nparts);
857 if (nparts < msgset->msg_part[i]) 857 if (nparts < msgset->msg_part[i])
858 { 858 {
...@@ -860,7 +860,7 @@ util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part) ...@@ -860,7 +860,7 @@ util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part)
860 msgset->msg_part[i]); 860 msgset->msg_part[i]);
861 return 1; 861 return 1;
862 } 862 }
863 863
864 if (message_get_part (mesg, msgset->msg_part[i], &submsg)) 864 if (message_get_part (mesg, msgset->msg_part[i], &submsg))
865 { 865 {
866 util_error ("can't get (sub)part from the message: %d", 866 util_error ("can't get (sub)part from the message: %d",
...@@ -874,20 +874,20 @@ util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part) ...@@ -874,20 +874,20 @@ util_descend_subparts (message_t mesg, msgset_t *msgset, message_t *part)
874 *part = mesg; 874 *part = mesg;
875 return 0; 875 return 0;
876 } 876 }
877 877
878 void 878 void
879 util_msgset_iterate (msgset_t *msgset, int (*fun)(), void *closure) 879 util_msgset_iterate (msgset_t *msgset, int (*fun)(), void *closure)
880 { 880 {
881 for (; msgset; msgset = msgset->next) 881 for (; msgset; msgset = msgset->next)
882 { 882 {
883 message_t mesg; 883 message_t mesg;
884 884
885 if (mailbox_get_message (mbox, msgset->msg_part[0], &mesg) != 0) 885 if (mailbox_get_message (mbox, msgset->msg_part[0], &mesg) != 0)
886 return; 886 return;
887 887
888 if (util_descend_subparts (mesg, msgset, &mesg) == 0) 888 if (util_descend_subparts (mesg, msgset, &mesg) == 0)
889 (*fun)(mesg, msgset, closure); 889 (*fun)(mesg, msgset, closure);
890 } 890 }
891 } 891 }
892 892
893 int 893 int
......
...@@ -31,7 +31,7 @@ mail_visual (int argc, char **argv) ...@@ -31,7 +31,7 @@ mail_visual (int argc, char **argv)
31 message_t msg = NULL; 31 message_t msg = NULL;
32 attribute_t attr = NULL; 32 attribute_t attr = NULL;
33 char *file = tempnam(getenv("TMPDIR"), "mu"); 33 char *file = tempnam(getenv("TMPDIR"), "mu");
34 34
35 util_do_command ("copy %s", file); /* NOTE: copy does not set flags */ 35 util_do_command ("copy %s", file); /* NOTE: copy does not set flags */
36 util_do_command ("shell %s %s", getenv("VISUAL"), file); 36 util_do_command ("shell %s %s", getenv("VISUAL"), file);
37 37
...@@ -42,7 +42,7 @@ mail_visual (int argc, char **argv) ...@@ -42,7 +42,7 @@ mail_visual (int argc, char **argv)
42 mailbox_get_message (mbox, cursor, &msg); 42 mailbox_get_message (mbox, cursor, &msg);
43 message_get_attribute (msg, &attr); 43 message_get_attribute (msg, &attr);
44 attribute_set_read (attr); 44 attribute_set_read (attr);
45 45
46 return 0; 46 return 0;
47 } 47 }
48 return 1; 48 return 1;
......
...@@ -37,7 +37,7 @@ mail_write (int argc, char **argv) ...@@ -37,7 +37,7 @@ mail_write (int argc, char **argv)
37 msgset_t *msglist = NULL, *mp; 37 msgset_t *msglist = NULL, *mp;
38 int sender = 0; 38 int sender = 0;
39 size_t total_size = 0, total_lines = 0, size; 39 size_t total_size = 0, total_lines = 0, size;
40 40
41 if (isupper (argv[0][0])) 41 if (isupper (argv[0][0]))
42 sender = 1; 42 sender = 1;
43 else if (argc >= 2) 43 else if (argc >= 2)
...@@ -73,7 +73,7 @@ mail_write (int argc, char **argv) ...@@ -73,7 +73,7 @@ mail_write (int argc, char **argv)
73 msgset_free (msglist); 73 msgset_free (msglist);
74 return 1; 74 return 1;
75 } 75 }
76 76
77 for (mp = msglist; mp; mp = mp->next) 77 for (mp = msglist; mp; mp = mp->next)
78 { 78 {
79 attribute_t attr; 79 attribute_t attr;
...@@ -85,7 +85,7 @@ mail_write (int argc, char **argv) ...@@ -85,7 +85,7 @@ mail_write (int argc, char **argv)
85 total_size += size; 85 total_size += size;
86 body_lines (bod, &size); 86 body_lines (bod, &size);
87 total_lines += size; 87 total_lines += size;
88 88
89 body_get_stream (bod, &stream); 89 body_get_stream (bod, &stream);
90 /* should there be a separator? */ 90 /* should there be a separator? */
91 while (stream_read(stream, buffer, sizeof (buffer) - 1, off, &n) == 0 91 while (stream_read(stream, buffer, sizeof (buffer) - 1, off, &n) == 0
...@@ -95,7 +95,7 @@ mail_write (int argc, char **argv) ...@@ -95,7 +95,7 @@ mail_write (int argc, char **argv)
95 fprintf (output, "%s", buffer); 95 fprintf (output, "%s", buffer);
96 off += n; 96 off += n;
97 } 97 }
98 98
99 /* mark as saved. */ 99 /* mark as saved. */
100 100
101 message_get_attribute (msg, &attr); 101 message_get_attribute (msg, &attr);
......
...@@ -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,56 +74,56 @@ int ...@@ -74,56 +74,56 @@ 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; 77 attr->flags &= ~MU_ATTRIBUTE_MODIFIED;
78 if (attr->_unset_flags)
79 attr->_unset_flags (attr, MU_ATTRIBUTE_MODIFIED);
80 attr->flags &= ~MU_ATTRIBUTE_MODIFIED;
81 return 0; 78 return 0;
82 } 79 }
83 80
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; 85 attr->flags |= MU_ATTRIBUTE_MODIFIED;
90 if (attr->_set_flags) 86 return 0;
91 status = attr->_set_flags (attr, MU_ATTRIBUTE_MODIFIED);
92 attr->flags |= MU_ATTRIBUTE_MODIFIED;
93 return status;
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) 96 *pflags = attr->flags;
104 *pflags = attr->flags;
105 return 0; 97 return 0;
106 } 98 }
107 99
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);
115 attr->flags |= flags; 108 else
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);
126 attr->flags &= ~flags; 123 else
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;
280 return 0; 234 if (attribute_get_flags (attr, &flags) == 0)
281 if (attr->_get_flags) 235 return flags & MU_ATTRIBUTE_SEEN;
282 attr->_get_flags (attr, &(attr->flags)); 236 return 0;
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;
290 return 0; 243 if (attribute_get_flags (attr, &flags) == 0)
291 if (attr->_get_flags) 244 return flags & MU_ATTRIBUTE_ANSWERED;
292 attr->_get_flags (attr, &(attr->flags)); 245 return 0;
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;
300 return 0; 252 if (attribute_get_flags (attr, &flags) == 0)
301 if (attr->_get_flags) 253 return flags & MU_ATTRIBUTE_FLAGGED;
302 attr->_get_flags (attr, &(attr->flags)); 254 return 0;
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;
310 return 0; 261 if (attribute_get_flags (attr, &flags) == 0)
311 if (attr->_get_flags) 262 return flags & MU_ATTRIBUTE_READ;
312 attr->_get_flags (attr, &(attr->flags)); 263 return 0;
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;
320 return 0; 270 if (attribute_get_flags (attr, &flags) == 0)
321 if (attr->_get_flags) 271 return flags & MU_ATTRIBUTE_DELETED;
322 attr->_get_flags (attr, &(attr->flags)); 272 return 0;
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;
330 return 0; 279 if (attribute_get_flags (attr, &flags) == 0)
331 if (attr->_get_flags) 280 return flags & MU_ATTRIBUTE_DRAFT;
332 attr->_get_flags (attr, &(attr->flags)); 281 return 0;
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)); 290 /* something is recent when it is not read and not seen. */
343 /* something is recent when it is not read and not seen. */ 291 return (flags == 0 || ! ((flags & MU_ATTRIBUTE_SEEN)
344 return (attr->flags == 0 292 || (flags & MU_ATTRIBUTE_READ)));
345 || ! ((attr->flags & MU_ATTRIBUTE_SEEN) 293 }
346 || (attr->flags & MU_ATTRIBUTE_READ))); 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 msg_imap->flags |= MU_ATTRIBUTE_SEEN; 1265 {
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) 503 CHECK_EAGAIN (f_imap, status);
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);
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 }
...@@ -1267,9 +1255,9 @@ imap_envelope_date (envelope_t envelope, char *buffer, size_t buflen, ...@@ -1267,9 +1255,9 @@ imap_envelope_date (envelope_t envelope, char *buffer, size_t buflen,
1267 if (now == (time_t)-1) 1255 if (now == (time_t)-1)
1268 { 1256 {
1269 struct tm* gmt; 1257 struct tm* gmt;
1270 1258
1271 time(&now); 1259 time(&now);
1272 1260
1273 gmt = gmtime(&now); 1261 gmt = gmtime(&now);
1274 1262
1275 tm = *gmt; 1263 tm = *gmt;
...@@ -1281,7 +1269,7 @@ imap_envelope_date (envelope_t envelope, char *buffer, size_t buflen, ...@@ -1281,7 +1269,7 @@ imap_envelope_date (envelope_t envelope, char *buffer, size_t buflen,
1281 /* FIXME: I don't know what strftime does if the buflen is too 1269 /* FIXME: I don't know what strftime does if the buflen is too
1282 short, or it fails. Assuming that it won't fail, this is my guess 1270 short, or it fails. Assuming that it won't fail, this is my guess
1283 as to the right thing. 1271 as to the right thing.
1284 1272
1285 I think if the buffer is too short, it will fill it as much 1273 I think if the buffer is too short, it will fill it as much
1286 as it can, and nul terminate it. But I'll terminate it anyhow. 1274 as it can, and nul terminate it. But I'll terminate it anyhow.
1287 */ 1275 */
...@@ -1290,7 +1278,7 @@ imap_envelope_date (envelope_t envelope, char *buffer, size_t buflen, ...@@ -1290,7 +1278,7 @@ imap_envelope_date (envelope_t envelope, char *buffer, size_t buflen,
1290 len = buflen - 1; 1278 len = buflen - 1;
1291 buffer[len] = 0; 1279 buffer[len] = 0;
1292 } 1280 }
1293 1281
1294 if(plen) 1282 if(plen)
1295 *plen = len; 1283 *plen = len;
1296 } 1284 }
......
...@@ -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
1229 if (mpm == NULL || pflags == NULL)
1230 return EINVAL;
1231 if (mpm->attr_flags == 0)
1232 {
1233 hdr_status[0] = '\0';
1234 message_get_header (mpm->message, &header);
1235 header_get_value (header, "Status", hdr_status, sizeof hdr_status, NULL);
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
1224 if (mpm == NULL) 1260 if (mpm == NULL)
1225 return EINVAL; 1261 return EINVAL;
1226 hdr_status[0] = '\0'; 1262 mpm->attr_flags &= ~flags;
1227 message_get_header (mpm->message, &header);
1228 header_get_value (header, "Status", hdr_status, sizeof (hdr_status), NULL);
1229 string_to_flags (hdr_status, pflags);
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,21 +50,22 @@ unsigned long mu_hex2ul(char hex) ...@@ -49,21 +50,22 @@ 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
56 *ul = 0; 58 *ul = 0;
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;
66 } 68 }
67 return r; 69 return r;
68 } 70 }
69 71
...@@ -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;
......
...@@ -1192,7 +1192,7 @@ int parse822_day(const char** p, const char* e, int* day) ...@@ -1192,7 +1192,7 @@ int parse822_day(const char** p, const char* e, int* day)
1192 1192
1193 if((e - *p) < 3) 1193 if((e - *p) < 3)
1194 return EPARSE; 1194 return EPARSE;
1195 1195
1196 for(d = 0; days[d]; d++) { 1196 for(d = 0; days[d]; d++) {
1197 if(strncasecmp(*p, days[d], 3) == 0) { 1197 if(strncasecmp(*p, days[d], 3) == 0) {
1198 *p += 3; 1198 *p += 3;
...@@ -1245,7 +1245,7 @@ int parse822_date(const char** p, const char* e, int* day, int* mon, int* year) ...@@ -1245,7 +1245,7 @@ int parse822_date(const char** p, const char* e, int* day, int* mon, int* year)
1245 1245
1246 if((e - *p) < 3) 1246 if((e - *p) < 3)
1247 return EPARSE; 1247 return EPARSE;
1248 1248
1249 for(m = 0; mons[m]; m++) { 1249 for(m = 0; mons[m]; m++) {
1250 if(strncasecmp(*p, mons[m], 3) == 0) { 1250 if(strncasecmp(*p, mons[m], 3) == 0) {
1251 *p += 3; 1251 *p += 3;
...@@ -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,8 +134,10 @@ main (int argc, char **argv) ...@@ -134,8 +134,10 @@ 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. */
140 signal (SIGINT, pop3d_signal); 142 signal (SIGINT, pop3d_signal);
141 signal (SIGQUIT, pop3d_signal); 143 signal (SIGQUIT, pop3d_signal);
...@@ -146,7 +148,7 @@ main (int argc, char **argv) ...@@ -146,7 +148,7 @@ main (int argc, char **argv)
146 signal (SIGTERM, pop3d_signal); 148 signal (SIGTERM, pop3d_signal);
147 signal (SIGSTOP, pop3d_signal); 149 signal (SIGSTOP, pop3d_signal);
148 signal (SIGPIPE, pop3d_signal); 150 signal (SIGPIPE, pop3d_signal);
149 signal (SIGABRT, pop3d_signal); 151 signal (SIGABRT, pop3d_signal);
150 152
151 if (mode == DAEMON) 153 if (mode == DAEMON)
152 pop3d_daemon_init (); 154 pop3d_daemon_init ();
...@@ -292,7 +294,7 @@ pop3d_mainloop (int infile, int outfile) ...@@ -292,7 +294,7 @@ pop3d_mainloop (int infile, int outfile)
292 294
293 /* Lets boogie. */ 295 /* Lets boogie. */
294 fprintf (ofile, "+OK POP3 Ready %s\r\n", md5shared); 296 fprintf (ofile, "+OK POP3 Ready %s\r\n", md5shared);
295 297
296 while (state != UPDATE) 298 while (state != UPDATE)
297 { 299 {
298 char *buf, *arg, *cmd; 300 char *buf, *arg, *cmd;
...@@ -399,7 +401,7 @@ pop3d_daemon (unsigned int maxchildren, unsigned int port) ...@@ -399,7 +401,7 @@ pop3d_daemon (unsigned int maxchildren, unsigned int port)
399 pid_t pid; 401 pid_t pid;
400 int listenfd, connfd; 402 int listenfd, connfd;
401 size_t size; 403 size_t size;
402 404
403 listenfd = socket (AF_INET, SOCK_STREAM, 0); 405 listenfd = socket (AF_INET, SOCK_STREAM, 0);
404 if (listenfd == -1) 406 if (listenfd == -1)
405 { 407 {
......
...@@ -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