Commit 2cfe74a5 2cfe74a504132495b4e124e04c6d33c8aefbfbc5 by Sergey Poznyakoff

Removed

1 parent 74a83b9f
1 # Makefile
2
3 CFLAGS = -g -I../include -Wall -I../lib
4 LDFLAGS = -g -static
5 # On QNX
6 LDLIBS = -lsocket
7 # On GNU/Linux (if compile with threads)
8 #LDLIBS = -lpthread
9
10 MULIBS = ../lib/.libs/libmailutils.a ../mailbox/.libs/libmailbox.a ../lib/.libs/libmailutils.a
11
12 EXES = addr mbox-explode mbox-dates mbox-auth url-parse mbox-check mimetest msg-send muemail
13
14 default: $(EXES)
15
16 $(EXES): $(MULIBS)
17
18 # example of parsing the date fields, prints all the incorrectly
19 # formatted dates in a mailbox.
20
21 bad-dates: mbox-dates
22 for m in ~/Mail/*; do ./mbox-dates $$m; done | tee bad-dates.out
23
24 # addr example and test
25
26 addr.test: addr
27 ./addr < Addrs > Addrs.test
28 @echo "---- There should be no differences! ----"
29 diff -C5 -u Addrs.good Addrs.test
30
31 # url example and test
32
33 url.test: url-parse
34 ./url-parse < Urls > Urls.test
35 @echo "---- There should be no differences! ----"
36 diff -u Urls.good Urls.test
37
38 # mimetest example and test
39 # TODO
40
41 # clean and empty
42
43 clean:
44 rm -f *.o
45
46 empty: clean
47 rm -f $(EXES)
48
1 #include <sys/types.h>
2 #include <sys/stat.h>
3
4 #include <errno.h>
5 #include <fcntl.h>
6 #include <limits.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <time.h>
11 #include <unistd.h>
12
13 #include <mailutils/address.h>
14 #include <mailutils/debug.h>
15 #include <mailutils/errno.h>
16 #include <mailutils/mailbox.h>
17 #include <mailutils/parse822.h>
18 #include <mailutils/registrar.h>
19 #include <mailutils/stream.h>
20
21 int
22 main (int argc, char **argv)
23 {
24 mailbox_t mbox;
25 size_t count = 0;
26 char *mboxname = argv[1];
27 int status;
28
29 /* Register desired mailbox formats. */
30 {
31 list_t bookie;
32 registrar_get_list (&bookie);
33 list_append (bookie, path_record);
34 list_append (bookie, pop_record);
35 list_append (bookie, imap_record);
36 }
37
38 if ((status = mailbox_create_default (&mbox, mboxname)) != 0)
39 {
40 fprintf (stderr, "could not create <%s>: %s\n",
41 mboxname, mu_errstring (status));
42 return status;
43 }
44
45 {
46 mu_debug_t debug;
47 mailbox_get_debug (mbox, &debug);
48 mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT);
49 }
50
51 if ((status = mailbox_open (mbox, MU_STREAM_READ)) != 0)
52 {
53 fprintf (stderr, "could not open <%s>: %s\n",
54 mboxname, mu_errstring (status));
55 mailbox_destroy (&mbox);
56 exit (1);
57 }
58
59 if ((status = mailbox_messages_count (mbox, &count)) != 0)
60 {
61 fprintf (stderr, "could not count <%s>: %s\n",
62 mboxname, mu_errstring (status));
63 mailbox_close (mbox);
64 mailbox_destroy (&mbox);
65 exit (1);
66 }
67
68 mailbox_close (mbox);
69 mailbox_destroy (&mbox);
70
71 printf("count %d messages in <%s>\n", count, mboxname);
72
73 return 0;
74 }
75
1 #include <sys/types.h>
2 #include <sys/stat.h>
3
4 #include <errno.h>
5 #include <fcntl.h>
6 #include <limits.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <time.h>
11 #include <unistd.h>
12
13 #include <mailutils/address.h>
14 #include <mailutils/debug.h>
15 #include <mailutils/errno.h>
16 #include <mailutils/header.h>
17 #include <mailutils/mailbox.h>
18 #include <mailutils/message.h>
19 #include <mailutils/parse822.h>
20 #include <mailutils/registrar.h>
21 #include <mailutils/stream.h>
22
23
24 static const char *
25 UserAgent (header_t hdr)
26 {
27 static char agent[128];
28 size_t sz;
29
30 if (header_get_value (hdr, "User-Agent", agent, sizeof (agent), &sz) == 0
31 && sz != 0)
32 return agent;
33
34 if (header_get_value (hdr, "X-Mailer", agent, sizeof (agent), &sz) == 0
35 && sz != 0)
36 return agent;
37
38 /* Some MUAs, like Pine, put their name in the Message-Id, so print it as
39 a last ditch attempt at getting an idea who produced the date. */
40 if (header_get_value (hdr, "Message-Id", agent, sizeof (agent), &sz) == 0
41 && sz != 0)
42 return agent;
43
44 return "unknown";
45 }
46
47 int
48 main (int argc, char **argv)
49 {
50 mailbox_t mbox;
51 size_t i;
52 size_t count = 0;
53 char *mboxname = argv[1];
54 int status;
55 int debug = 0;
56
57 if (strcmp ("-d", mboxname) == 0)
58 {
59 mboxname = argv[2];
60 debug = 1;
61 }
62
63 if (mboxname == NULL)
64 {
65 printf ("Usage: mbox-dates [-d] <mbox>\n");
66 exit (1);
67 }
68
69 /* Register desired mailbox formats. */
70 {
71 list_t bookie;
72 registrar_get_list (&bookie);
73 list_append (bookie, path_record);
74 list_append (bookie, pop_record);
75 list_append (bookie, imap_record);
76 }
77
78 if ((status = mailbox_create_default (&mbox, mboxname)) != 0)
79 {
80 fprintf (stderr, "could not create <%s>: %s\n",
81 mboxname, mu_errstring (status));
82 exit (1);
83 }
84
85 if (debug)
86 {
87 mu_debug_t debug;
88 mailbox_get_debug (mbox, &debug);
89 mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT);
90 }
91
92 if ((status = mailbox_open (mbox, MU_STREAM_READ)) != 0)
93 {
94 fprintf (stderr, "could not open mbox: %s\n", mu_errstring (status));
95 exit (1);
96 }
97
98 mailbox_messages_count (mbox, &count);
99
100 for (i = 1; i <= count; ++i)
101 {
102 message_t msg;
103 header_t hdr;
104 char date[128];
105 size_t len = 0;
106
107 if ((status = mailbox_get_message (mbox, i, &msg)) != 0 ||
108 (status = message_get_header (msg, &hdr)) != 0)
109 {
110 printf ("%s, msg %d: %s\n", mboxname, i, mu_errstring (status));
111 continue;
112 }
113 if ((status =
114 header_get_value (hdr, MU_HEADER_DATE, date, sizeof (date),
115 &len)) != 0)
116 {
117 printf ("%s, msg %d: NO DATE (mua? %s)\n",
118 mboxname, i, UserAgent (hdr));
119 continue;
120 }
121 else
122 {
123 const char *s = date;
124
125 if (parse822_date_time (&s, s + strlen (s), NULL, NULL))
126 {
127 printf ("%s, msg %d: BAD DATE <%s> (mua? %s)\n",
128 mboxname, i, date, UserAgent (hdr));
129 continue;
130 }
131 }
132 }
133
134 mailbox_close (mbox);
135 mailbox_destroy (&mbox);
136
137 return status;
138 }
1 #include <sys/types.h>
2 #include <sys/stat.h>
3
4 #include <assert.h>
5 #include <errno.h>
6 #include <fcntl.h>
7 #include <limits.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <time.h>
12 #include <unistd.h>
13
14 #include <mailutils/debug.h>
15 #include <mailutils/errno.h>
16 #include <mailutils/list.h>
17 #include <mailutils/mailbox.h>
18 #include <mailutils/registrar.h>
19 #include <mailutils/stream.h>
20 #include <mailutils/message.h>
21
22 int
23 main (int argc, char **argv)
24 {
25 mailbox_t mbox;
26 size_t msgno;
27 size_t count = 0;
28 char *mbox_name = 0;
29 char *dir_name = 0;
30 int status;
31 int debug = 0;
32
33 if (strcmp("-d", argv[1]) == 0 && argc == 4)
34 {
35 debug = 1;
36 argc--;
37 argv[1] = argv[2];
38 argv[2] = argv[3];
39 }
40 if (argc != 3)
41 {
42 printf ("usage: mbox-explode <mbox> <directory>\n");
43 exit (0);
44 }
45 mbox_name = argv[1];
46 dir_name = argv[2];
47
48 /* Register the desire formats. */
49 {
50 list_t bookie;
51 registrar_get_list (&bookie);
52 list_append (bookie, path_record);
53 list_append (bookie, imap_record);
54 }
55
56 if ((status = mailbox_create_default (&mbox, mbox_name)) != 0)
57 {
58 fprintf (stderr, "could not create <%s>: %s\n",
59 mbox_name, mu_errstring (status));
60 exit (1);
61 }
62 if(debug)
63 {
64 mu_debug_t debug;
65 mailbox_get_debug (mbox, &debug);
66 mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT);
67 }
68
69 if ((status = mailbox_open (mbox, MU_STREAM_READ)) != 0)
70 {
71 fprintf (stderr, "could not open <%s>: %s\n",
72 mbox_name, mu_errstring (status));
73 exit (1);
74 }
75 mailbox_messages_count (mbox, &count);
76
77 if (mkdir (dir_name, 0777) != 0)
78 {
79 fprintf (stderr, "mkdir(%s) failed: %s\n", dir_name, strerror (errno));
80 mailbox_close (mbox);
81 exit (1);
82 }
83
84 for (msgno = 1; msgno <= count; ++msgno)
85 {
86 message_t msg = 0;
87 size_t nparts = 0;
88 size_t partno;
89
90 if ((status = mailbox_get_message (mbox, msgno, &msg)) != 0)
91 {
92 fprintf (stderr, "msg %d: get message failed: %s\n",
93 msgno, mu_errstring (status));
94 mailbox_close (mbox);
95 exit (1);
96 }
97 if ((status = message_get_num_parts (msg, &nparts)))
98 {
99 fprintf (stderr, "msg %d: get num parts failed: %s\n",
100 msgno, mu_errstring (status));
101 mailbox_close (mbox);
102 exit (1);
103 }
104 printf ("msg %03d: %02d parts\n", msgno, nparts);
105
106 for (partno = 1; partno <= nparts; partno++)
107 {
108 message_t part = 0;
109 char path[128];
110
111 sprintf (path, "%s/m%03d.p%02d", dir_name, msgno, partno);
112
113 printf ("msg %03d: part %02d > %s\n", msgno, partno, path);
114
115 if ((status = message_get_part (msg, partno, &part)))
116 {
117 fprintf (stderr, "msg %d: get part %d failed: %s\n",
118 msgno, partno, mu_errstring (status));
119 mailbox_close (mbox);
120 exit (1);
121 }
122 if ((status = message_save_attachment (part, path, 0)))
123 {
124 fprintf (stderr, "msg %d part %d: save failed: %s\n",
125 msgno, partno, mu_errstring (status));
126 break;
127 }
128 }
129 }
130
131 mailbox_close (mbox);
132 mailbox_destroy (&mbox);
133
134 return status;
135 }
136