Commit 86906fca 86906fca462365bdb70af844e17384ca5db6063a by Alain Magloire

* configure.in: We were not checking for thread support

	at all because the test was faulty.

	* readmsg: New directory.
	* readmsg/readmsg.c: New file.
	* readmsg/readmsg.h: New file.
	* readmsg/msglist.c: New file.
	This is base on a old testing program Dave inglis wrote
	to test the mime parsing code.  It is still work in progress
	but a good base for the readmsg(1) utility clone.
	Not enable yet in the TOP Makefile.
1 parent a273efe0
1 2001-06-27 Alain Magloire
2
3 * configure.in: We were not checking for thread support
4 at all because the test was faulty.
5
6 * readmsg: New directory.
7 * readmsg/readmsg.c: New file.
8 * readmsg/readmsg.h: New file.
9 * readmsg/msglist.c: New file.
10 This is base on a old testing program Dave inglis wrote
11 to test the mime parsing code. It is still work in progress
12 but a good base for the readmsg(1) utility close.
13 Not enable yet in the TOP Makefile.
14
1 2001-06-26 Alain Magloire 15 2001-06-26 Alain Magloire
2 16
3 * mail/from.c: Use address_get_personal() for a more 17 * mail/from.c: Use address_get_personal() for a more
4 pretty print when showing the headers. 18 pretty print when showing the headers.
5 19
6
7 2001-06-26 Sergey Poznyakoff 20 2001-06-26 Sergey Poznyakoff
8 * mail/util.c: 21 * mail/util.c:
9 Added extra argument to util_msglist_command(), controlling 22 Added extra argument to util_msglist_command(), controlling
......
...@@ -127,7 +127,7 @@ AC_SUBST(AUTHLIBS) ...@@ -127,7 +127,7 @@ AC_SUBST(AUTHLIBS)
127 dnl Check threading support 127 dnl Check threading support
128 # We have to rearrange things a little, it appears that the new autoconf 128 # We have to rearrange things a little, it appears that the new autoconf
129 # does not like long cascading AC_CHECK_LIB. 129 # does not like long cascading AC_CHECK_LIB.
130 if test x"$enable_threads" = x"yes" -a x"$usepthread" = x"yes"; then 130 if test x"$usepthread" = x"yes"; then
131 AC_CHECK_LIB(pthread, pthread_cancel, have_libpthread=yes 131 AC_CHECK_LIB(pthread, pthread_cancel, have_libpthread=yes
132 have_libpthread=no) 132 have_libpthread=no)
133 if test x"$have_libpthread" = x"yes"; then 133 if test x"$have_libpthread" = x"yes"; then
......
1 AUTOMAKE_OPTIONS = ../lib/ansi2knr
2 INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/lib
3
4 bin_PROGRAMS = readmsg
5
6 readmsg_SOURCES = readmsg.c msglist.c readmsg.h
7 readmsg_DEPENDENCIES = ../mailbox/libmailbox.la
8 readmsg_LDADD = ../mailbox/libmailbox.la ../lib/libmailutils.a
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 #include <errno.h>
19 #include <sys/types.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <mailutils/mailbox.h>
23
24 extern mailbox_t mbox;
25 extern unsigned int total;
26
27 static int
28 addset (int **set, int *n, unsigned val)
29 {
30 int *tmp;
31 tmp = realloc (*set, (*n + 1) * sizeof (**set));
32 if (tmp == NULL)
33 {
34 if (*set)
35 free (*set);
36 *n = 0;
37 *set = NULL;
38 return ENOMEM;
39 }
40 *set = tmp;
41 (*set)[*n] = val;
42 (*n)++;
43 return 0;
44 }
45
46 int
47 msgset (const int argc, char **argv, int **set, int *n)
48 {
49 int i = 0, lc = 0;
50 int undelete = 0;
51 int *ret = NULL;
52
53 for (i = 0; i < argc; i++)
54 {
55 /* Last message */
56 if (!strcmp (argv[i], "$") || !strcmp (argv[i], "0"))
57 {
58 addset (set, n, total);
59 }
60 else if (!strcmp (argv[i], "*"))
61 {
62 /* all messages */
63 for (i = 1; i <= total; i++)
64 addset (set, n, i);
65 i = argc + 1;
66 }
67 else if (argv[i][0] == '/')
68 {
69 /* FIXME: all messages with pattern following / in
70 the subject line, case insensitive */
71 /* This currently appears to be quit b0rked */
72 message_t msg;
73 header_t hdr;
74 char subj[128];
75 int j = 1, k = 0, len2 = 0;
76 int len = strlen (&argv[i][1]);
77 for (j = 1; j <= total; j++)
78 {
79 mailbox_get_message (mbox, j, &msg);
80 message_get_header (msg, &hdr);
81 header_get_value (hdr, MU_HEADER_SUBJECT, subj, 128, NULL);
82 len2 = strlen (subj);
83 for (k = 0; i < strlen (subj); k++)
84 {
85 if (len2 - k >= len
86 && !strncasecmp (&argv[i][1], &subj[k], len))
87 {
88 addset (set, n, j);
89 k = 128;
90 }
91 }
92 }
93 }
94 else if (isalpha(argv[i][0]))
95 {
96 /* FIXME: all messages from sender argv[i] */
97 }
98 else if (strchr (argv[i], '-') != NULL)
99 {
100 /* message range */
101 int j, x, y;
102 char *arg = strdup (argv[i]);
103 for (j = 0; j < strlen (arg); j++)
104 if (arg[j] == '-')
105 break;
106 arg[j] = '\0';
107 x = strtol (arg, NULL, 10);
108 y = strtol (&(arg[j + 1]), NULL, 10);
109 for (; x <= y; x++)
110 addset (set, n, x);
111 free (arg);
112 }
113 else
114 {
115 /* single message */
116 addset (set, n, strtol (argv[i], NULL, 10));
117 }
118 }
119
120 return 0;
121 }
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 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
21
22
23 #include "readmsg.h"
24
25 mailbox_t mbox;
26 size_t total;
27
28 static char from[256];
29 static char subject[256];
30
31 static void display_parts (message_t, const char *indent);
32
33 /* This is still work in progress */
34 int
35 main(int argc, char **argv)
36 {
37 int status;
38 int *set = NULL;
39 int n = 0;
40 size_t i;
41 char *mailbox_name = NULL;
42
43 /* FIXME: Parse options: See readmsg(1) part of elm:
44 readmsg 1 3 0
45 extracts three messages from the folder: the first, the third, and
46 the last. */
47
48 /* Check this in the option --folder. */
49
50 /* Registration. */
51 {
52 list_t bookie;
53 registrar_get_list (&bookie);
54 list_append (bookie, mbox_record);
55 list_append (bookie, path_record);
56 list_append (bookie, pop_record);
57 list_append (bookie, imap_record);
58 }
59
60 status = mailbox_create_default (&mbox, mailbox_name);
61 if (status != 0)
62 {
63 fprintf (stderr, "could not create - %s\n", strerror(status));
64 exit (2);
65 }
66
67 /* Debuging Trace. */
68 if ( 0 )
69 {
70 debug_t debug;
71 mailbox_get_debug (mbox, &debug);
72 debug_set_level (debug, MU_DEBUG_TRACE|MU_DEBUG_PROT);
73 }
74
75 status = mailbox_open (mbox, MU_STREAM_READ);
76 if (status != 0)
77 {
78 fprintf (stderr, "could not open - %s\n", strerror(status));
79 exit (2);
80 }
81
82 mailbox_messages_count (mbox, &total);
83
84 /* Build an array containing the message number. */
85 if (argc > 1)
86 msgset (argc - 1, &argv[1], &set, &n);
87 else
88 {
89 char *av[] = { "*" };
90 msgset (1, av, &set, &n);
91 }
92
93 for (i = 0; i < n; ++i)
94 {
95 message_t msg;
96 header_t hdr;
97 size_t msize;
98
99 status = mailbox_get_message (mbox, set[i], &msg);
100 if (status != 0)
101 {
102 fprintf (stderr, "mailbox_get_message - %s\n", strerror (status));
103 exit (2);
104 }
105
106 status = message_get_header (msg, &hdr);
107 if (status != 0)
108 {
109 fprintf (stderr, "message_get_header - %s\n", strerror(status));
110 exit(2);
111 }
112
113 header_get_value (hdr, MU_HEADER_FROM, from, sizeof (from), NULL);
114 header_get_value (hdr, MU_HEADER_SUBJECT, subject, sizeof (subject),
115 NULL);
116 fprintf(stdout, "From: %s\tSubject: %s\n", from, subject);
117
118 status = message_size (msg, &msize);
119 if (status != 0)
120 {
121 fprintf (stderr, "message_size - %s\n", strerror(status));
122 exit(2);
123 }
124 fprintf (stdout, "-- Total message size - %d\n", msize);
125
126 display_parts (msg, "\t");
127 }
128 mailbox_close (mbox);
129 mailbox_destroy (&mbox);
130 return 0;
131 }
132
133 static char buf[2048];
134
135 static void
136 display_parts (message_t message, const char *indent)
137 {
138 int status, j;
139 size_t msize, nparts;
140 message_t msg;
141 header_t hdr;
142 char type[256];
143 char encoding[256];
144 int is_multi = 0;
145 char *nl;
146
147 status = message_get_num_parts (message, &nparts);
148 if (status != 0)
149 {
150 fprintf (stderr, "message_get_num_parts - %s\n", strerror (status));
151 exit (2);
152 }
153 fprintf(stdout, "%s-- Number of parts in message - %d\n", indent, nparts);
154
155 for (j = 1; j <= nparts; j++)
156 {
157 status = message_get_part (message, j, &msg);
158 if (status != 0 )
159 {
160 fprintf (stderr, "message_get_part - %s\n", strerror (status));
161 exit (2);
162 }
163
164 status = message_get_header (msg, &hdr);
165 if (status != 0)
166 {
167 fprintf (stderr, "message_get_header - %s\n", strerror (status));
168 exit (2);
169 }
170
171 type[0] = '\0';
172 header_get_value (hdr, MU_HEADER_CONTENT_TYPE, type, sizeof (type),
173 NULL);
174
175 nl = strchr (type, '\n');
176 while ((nl = strchr (type, '\n')) != NULL)
177 {
178 *nl = ' ';
179 }
180 fprintf(stdout, "%sType of part %d = %s\n", indent, j, type);
181
182 status = message_size (msg, &msize);
183 if (status != 0)
184 {
185 fprintf (stderr, "message_size - %s\n", strerror (status));
186 exit (2);
187 }
188 fprintf(stdout, "%sMessage part size - %d\n",indent, msize);
189
190 encoding[0] = '\0';
191 header_get_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING, encoding,
192 sizeof (encoding), NULL);
193
194 if (type[0] && strncasecmp (type, "message/rfc822", strlen (type)) == 0)
195 {
196 message_t submsg = NULL;
197 char tmp[10];
198 tmp[0] = '\0';
199
200 status = message_unencapsulate (msg, &submsg, NULL);
201 if (status != 0)
202 {
203 fprintf (stderr, "message_unencapsulate - %s\n", strerror (status));
204 exit (2);
205 }
206
207 status = message_get_header (submsg, &hdr);
208 if (status != 0)
209 {
210 fprintf (stderr, "message_get_header - %s\n", strerror (status));
211 exit (2);
212 }
213
214 header_get_value (hdr, MU_HEADER_FROM, from, sizeof (from), NULL);
215 header_get_value (hdr, MU_HEADER_SUBJECT, subject, sizeof (subject),
216 NULL);
217 fprintf (stdout, "%sEncapsulated message : %s\t%s\n", indent, from,
218 subject);
219 fprintf (stdout, "%s----------------------------------------------\
220 ---------------------\n", indent);
221
222 strcpy (tmp, indent);
223 strcat (tmp,"\t");
224 display_parts (submsg, tmp);
225 message_destroy (&submsg, NULL);
226 }
227 else if ((strncasecmp (type, "text/plain", strlen ("text/plain")) == 0)
228 || (strncasecmp (type, "text/html", strlen ("text/html")) == 0))
229 {
230 stream_t d_stream = NULL;
231 stream_t b_stream = NULL;
232 body_t body;
233 size_t nbytes = 0;
234 int offset = 0;
235 fprintf (stdout, "%sText Message\n",indent);
236 fprintf (stdout, "%s-------------------------------------------------------------------\n", indent);
237 message_get_body (msg, &body);
238 body_get_stream (body, &b_stream);
239 //d_stream = b_stream;
240 //status = decoder_stream_create(&d_stream, b_stream, encoding);
241 status = filter_create (&d_stream, b_stream, encoding, 0, 0);
242 stream_setbufsiz (d_stream, 128);
243 if (status != 0)
244 {
245 d_stream = b_stream;
246 }
247 while (stream_readline (d_stream, buf, sizeof (buf),
248 offset, &nbytes ) == 0 && nbytes )
249 {
250 fprintf (stdout, "%s%s", indent, buf);
251 offset += nbytes;
252 }
253 if (status == 0)
254 stream_destroy(&d_stream, NULL);
255 }
256 else
257 {
258 message_is_multipart (msg, &is_multi);
259 if (is_multi)
260 {
261 char tmp[24];
262 memset (tmp, '\0', sizeof (tmp));
263 strcpy(tmp, indent);
264 strcat(tmp,"\t");
265 display_parts (msg, tmp);
266 }
267 else
268 {
269 body_t body = NULL;
270 stream_t stream = NULL;
271 size_t nbytes = 0;
272 int offset = 0;
273 message_get_body (msg, &body);
274 body_get_stream (body, &stream);
275 #if 0
276 while (stream_readline (stream, buf, sizeof (buf),
277 offset, &nbytes ) == 0 && nbytes )
278 {
279 fprintf (stdout, "%s%s", indent, buf);
280 offset += nbytes;
281 }
282 #endif
283 }
284 #if 0
285 {
286 char *fname;
287 message_attachment_filename ( msg, &fname);
288 if ( fname == NULL )
289 {
290 char buffer[PATH_MAX+1];
291 fname = tempnam (getcwd(buffer, PATH_MAX), "msg-" );
292 }
293 fprintf (stdout, "%sAttachment - saving [%s]\n",indent, fname);
294 fprintf (stdout, "%s-------------------------------------------------------------------\n", indent);
295 message_save_attachment (msg, fname, NULL);
296 free (fname);
297 }
298 #endif
299
300 }
301 fprintf(stdout, "\n%s End -------------------------------------------------------------------\n", indent);
302 }
303 }
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 #ifndef _READMSG_H
19 #define _REAMSG_H
20
21 #include <sys/types.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <limits.h>
27
28 #include <mailutils/mailbox.h>
29 #include <mailutils/header.h>
30 #include <mailutils/mime.h>
31 #include <mailutils/filter.h>
32 #include <mailutils/registrar.h>
33
34 extern mailbox_t mbox;
35 extern size_t total;
36
37 #endif