Instead of writing the documentation, found a diversion "frm" is a clone
to the "frm" that comes with elm package. It was written in less then 15 minutes, cool.
Showing
5 changed files
with
340 additions
and
0 deletions
... | @@ -17,7 +17,9 @@ | ... | @@ -17,7 +17,9 @@ |
17 | 17 | ||
18 | /* Define if using libpam */ | 18 | /* Define if using libpam */ |
19 | #undef USE_LIBPAM | 19 | #undef USE_LIBPAM |
20 | |||
20 | #undef HAVE_SNPRINTF | 21 | #undef HAVE_SNPRINTF |
22 | |||
21 | #undef WITH_PTHREAD | 23 | #undef WITH_PTHREAD |
22 | 24 | ||
23 | /* Define if using libreadline */ | 25 | /* Define if using libreadline */ | ... | ... |
frm/Makefile.am
0 → 100644
frm/frm.c
0 → 100644
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 | #include <sys/types.h> | ||
23 | #include <stdio.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <string.h> | ||
26 | #include <unistd.h> | ||
27 | #include "getopt.h" | ||
28 | |||
29 | #include <mailutils/mailbox.h> | ||
30 | #include <mailutils/header.h> | ||
31 | #include <mailutils/registrar.h> | ||
32 | #include <mailutils/observer.h> | ||
33 | #include <mailutils/address.h> | ||
34 | |||
35 | static int action (observer_t, size_t); | ||
36 | static int counter; | ||
37 | |||
38 | static struct option long_options[] = | ||
39 | { | ||
40 | {"help", no_argument, 0, 'h'}, | ||
41 | {"to", no_argument, 0, 'l'}, | ||
42 | {"number", no_argument, 0, 'n'}, | ||
43 | {"Quiet", no_argument, 0, 'Q'}, | ||
44 | {"query", no_argument, 0, 'q'}, | ||
45 | {"status", required_argument, 0, 's'}, | ||
46 | {"align", no_argument, 0, 't'}, | ||
47 | {"version", no_argument, 0, 'v'}, | ||
48 | {0, 0, 0, 0} | ||
49 | }; | ||
50 | |||
51 | const char *short_options ="hlnQqs:tv"; | ||
52 | |||
53 | static int show_to; | ||
54 | static int show_from = 1; | ||
55 | static int show_subject = 1; | ||
56 | static int show_number; | ||
57 | static int show_summary; | ||
58 | static int be_quiet; | ||
59 | static int be_silent; | ||
60 | static int align = 1; | ||
61 | static int show_query; | ||
62 | static int have_new_mail; | ||
63 | |||
64 | #define IS_READ 0x001 | ||
65 | #define IS_OLD 0x010 | ||
66 | #define IS_NEW 0x100 | ||
67 | static int select_attribute; | ||
68 | |||
69 | static int counter; | ||
70 | |||
71 | |||
72 | /* Retrieve the Personal Name from the header To: or From: */ | ||
73 | static int | ||
74 | get_personal (header_t hdr, char *field, char *personal, size_t buflen) | ||
75 | { | ||
76 | char hfield[512]; | ||
77 | int status; | ||
78 | |||
79 | /* Empty string. */ | ||
80 | *hfield = '\0'; | ||
81 | |||
82 | status = header_get_value (hdr, field, hfield, sizeof (hfield), NULL); | ||
83 | if (status == 0) | ||
84 | { | ||
85 | address_t address = NULL; | ||
86 | size_t len = 0; | ||
87 | address_create (&address, hfield); | ||
88 | address_get_personal (address, 1, personal, buflen, &len); | ||
89 | address_destroy (&address); | ||
90 | if (len == 0) | ||
91 | strncpy (personal, hfield, buflen)[buflen - 1] = '\0'; | ||
92 | } | ||
93 | return status; | ||
94 | } | ||
95 | |||
96 | /* Observable Action this is being call at every message discover. */ | ||
97 | /* FIXME: The format of the display is poorly done, please correct. */ | ||
98 | static int | ||
99 | action (observer_t o, size_t type) | ||
100 | { | ||
101 | switch (type) | ||
102 | { | ||
103 | case MU_EVT_MESSAGE_ADD: | ||
104 | { | ||
105 | mailbox_t mbox = observer_get_owner (o); | ||
106 | message_t msg = NULL; | ||
107 | header_t hdr = NULL; | ||
108 | attribute_t attr = NULL; | ||
109 | char hsubject[512]; | ||
110 | |||
111 | counter++; | ||
112 | |||
113 | mailbox_get_message (mbox, counter, &msg); | ||
114 | |||
115 | message_get_attribute (msg, &attr); | ||
116 | message_get_header (msg, &hdr); | ||
117 | |||
118 | if (select_attribute | ||
119 | && (select_attribute & IS_READ) | ||
120 | && (!attribute_is_read (attr))) | ||
121 | { | ||
122 | break; | ||
123 | } | ||
124 | else if (select_attribute | ||
125 | && (select_attribute & IS_NEW) | ||
126 | && (!attribute_is_recent (attr))) | ||
127 | { | ||
128 | break; | ||
129 | } | ||
130 | else if (select_attribute | ||
131 | && (select_attribute & IS_OLD) | ||
132 | && (!attribute_is_seen (attr))) | ||
133 | { | ||
134 | break; | ||
135 | } | ||
136 | |||
137 | if (attribute_is_recent (attr)) | ||
138 | have_new_mail = 1; | ||
139 | |||
140 | if (be_quiet) | ||
141 | break; | ||
142 | |||
143 | |||
144 | if (show_number) | ||
145 | printf ("%d: ", counter); | ||
146 | |||
147 | if (show_to) | ||
148 | { | ||
149 | char hto[16]; | ||
150 | int status = get_personal (hdr, MU_HEADER_TO, hto, sizeof (hto)); | ||
151 | if (status == 0) | ||
152 | printf ("(%s) ", hto); | ||
153 | else | ||
154 | printf ("(------)"); | ||
155 | } | ||
156 | |||
157 | if (show_from) | ||
158 | { | ||
159 | char hfrom[32]; | ||
160 | int status = get_personal (hdr, MU_HEADER_FROM, hfrom, | ||
161 | sizeof (hfrom)); | ||
162 | if (status == 0) | ||
163 | printf ("%s\t", hfrom); | ||
164 | else | ||
165 | printf ("-----\t"); | ||
166 | } | ||
167 | |||
168 | if (show_subject) | ||
169 | { | ||
170 | char hsubject[64]; | ||
171 | int status = header_get_value (hdr, MU_HEADER_SUBJECT, hsubject, | ||
172 | sizeof (hsubject), NULL); | ||
173 | printf("%s\n", hsubject); | ||
174 | } | ||
175 | break; | ||
176 | } | ||
177 | |||
178 | case MU_EVT_MAILBOX_PROGRESS: | ||
179 | /* Noop. */ | ||
180 | break; | ||
181 | } | ||
182 | return 0; | ||
183 | } | ||
184 | |||
185 | void | ||
186 | usage (const char *argv) | ||
187 | { | ||
188 | printf ("GNU Mailutils.\n"); | ||
189 | printf ("Usage: %s [OPTIONS]\n\n", argv); | ||
190 | printf (" -h, --help display this help and exit\n"); | ||
191 | printf (" -l, --to include the To: information\n"); | ||
192 | printf (" -n, --number display the message numberd\n"); | ||
193 | printf (" -Q, --Quiet very quiet\n"); | ||
194 | printf (" -q, --query print a message if unread mail\n"); | ||
195 | printf (" -s, --status=[nor] select message with the specific \ | ||
196 | attribute\n"); | ||
197 | printf (" [n]ew, [r]ead, [u]nread.\n"); | ||
198 | printf (" -t, --align Try to align\n"); | ||
199 | printf (" -v, --version display version information and exit\n"); | ||
200 | printf ("\nReport bugs to bug-mailutils@gnu.org\n"); | ||
201 | exit (0); | ||
202 | } | ||
203 | |||
204 | /* This a close of the elm program call "frm". It is a good example on | ||
205 | how to use the observable(callback) of libmailutils. "frm" has to | ||
206 | be very interactive so it is not possible to call mailbox_messages_count() | ||
207 | and wait for the scanning to finish before displaying. As soon as the scan | ||
208 | find a new message we want to know about it, this is done by registering | ||
209 | an observable type MU_MAILBOX_NEW_MSG. The rest is simple displaying | ||
210 | formating code. */ | ||
211 | |||
212 | int | ||
213 | main(int argc, char **argv) | ||
214 | { | ||
215 | char *mailbox_name = NULL; | ||
216 | int c; | ||
217 | |||
218 | while ((c = getopt_long (argc, argv, short_options, long_options, NULL)) | ||
219 | != -1) | ||
220 | { | ||
221 | switch (c) | ||
222 | { | ||
223 | case 'h': | ||
224 | usage (argv[0]); | ||
225 | break; | ||
226 | |||
227 | case 'l': | ||
228 | show_to = 1; | ||
229 | break; | ||
230 | |||
231 | case 'n': | ||
232 | show_number = 1; | ||
233 | break; | ||
234 | |||
235 | case 'Q': | ||
236 | /* Very silent. */ | ||
237 | be_quiet += 2; | ||
238 | break; | ||
239 | |||
240 | case 'q': | ||
241 | be_quiet = show_query = 1; | ||
242 | break; | ||
243 | |||
244 | case 'S': | ||
245 | show_summary = 1; | ||
246 | break; | ||
247 | |||
248 | case 's': | ||
249 | if (optarg) | ||
250 | switch (*optarg) | ||
251 | { | ||
252 | case 'r': | ||
253 | select_attribute |= IS_READ; | ||
254 | break; | ||
255 | |||
256 | case 'o': | ||
257 | select_attribute |= IS_OLD; | ||
258 | break; | ||
259 | |||
260 | case 'n': | ||
261 | select_attribute |= IS_NEW; | ||
262 | break; | ||
263 | |||
264 | } | ||
265 | break; | ||
266 | |||
267 | case 't': | ||
268 | align = 1; | ||
269 | break; | ||
270 | |||
271 | case 'v': | ||
272 | printf ("Mailutils 0.0.0: frm\n"); | ||
273 | exit (0); | ||
274 | break; | ||
275 | |||
276 | default: | ||
277 | break; | ||
278 | } | ||
279 | } | ||
280 | |||
281 | /* have an argument */ | ||
282 | if (optind < argc) | ||
283 | mailbox_name = argv[optind]; | ||
284 | |||
285 | /* register the formats. */ | ||
286 | { | ||
287 | list_t bookie; | ||
288 | registrar_get_list (&bookie); | ||
289 | list_append (bookie, mbox_record); | ||
290 | list_append (bookie, path_record); | ||
291 | list_append (bookie, pop_record); | ||
292 | list_append (bookie, imap_record); | ||
293 | } | ||
294 | |||
295 | /* Construct the mailbox_t, attach a notification and destroy */ | ||
296 | { | ||
297 | mailbox_t mbox; | ||
298 | observer_t observer; | ||
299 | observable_t observable; | ||
300 | int status; | ||
301 | |||
302 | if ((status = mailbox_create_default (&mbox, mailbox_name) != 0) | ||
303 | || (status = mailbox_open (mbox, MU_STREAM_READ) != 0)) | ||
304 | { | ||
305 | fprintf (stderr, "could not open mailbox\n"); | ||
306 | exit (1); | ||
307 | } | ||
308 | |||
309 | observer_create (&observer, mbox); | ||
310 | observer_set_action (observer, action, mbox); | ||
311 | mailbox_get_observable (mbox, &observable); | ||
312 | observable_attach (observable, MU_EVT_MESSAGE_ADD, observer); | ||
313 | |||
314 | mailbox_scan (mbox, 1, NULL); | ||
315 | |||
316 | observable_detach (observable, observer); | ||
317 | observer_destroy (&observer, mbox); | ||
318 | |||
319 | mailbox_close(mbox); | ||
320 | mailbox_destroy(&mbox); | ||
321 | } | ||
322 | |||
323 | if (show_summary && be_quiet < 1) | ||
324 | printf ("You have %d messages\n", counter); | ||
325 | if (show_query && have_new_mail) | ||
326 | printf ("You have new mail\n"); | ||
327 | return 0; | ||
328 | } |
lib/alloca.c
0 → 100644
This diff is collapsed.
Click to expand it.
... | @@ -17,6 +17,9 @@ | ... | @@ -17,6 +17,9 @@ |
17 | 17 | ||
18 | /* Tell GLIBC that we want UNIX98 pthread_rwlock_xx() functions. */ | 18 | /* Tell GLIBC that we want UNIX98 pthread_rwlock_xx() functions. */ |
19 | #define _XOPEN_SOURCE 500 | 19 | #define _XOPEN_SOURCE 500 |
20 | /* Tell QNX/Neutrino to define pthread_rwlock_xx() functions. */ | ||
21 | #define _QNX_SOURCE | ||
22 | #define _POSIX_C_SOURCE 199506 | ||
20 | #ifdef HAVE_CONFIG_H | 23 | #ifdef HAVE_CONFIG_H |
21 | # include <config.h> | 24 | # include <config.h> |
22 | #endif | 25 | #endif | ... | ... |
-
Please register or sign in to post a comment