sfrom.c.texi
1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* sfrom, Simple From */
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <mailutils.h>
int main (int argc, char **argv)
@{
char buffer[1024];
char from[64];
char subject[64];
char *mail;
mailbox_t mbox;
int status
size_t msgno, msg_total, size;
mail = (argc == 2) ? argv[1] : getenv ("MAIL");
status = mailbox_init_default (&mbox, mail);
if (status != 0)
@{
fprintf (stderr, "mailbox_init(%s) failed\n",
mail ? mail : "Default");
exit (EXIT_FAILURE);
@}
status = mailbox_open (mbox, MU_MB_ORDONLY);
if (status != 0)
@{
fprintf (stderr, "mailbox_open(%s), %s\n", mail);
exit (EXIT_FAILURE);
@}
mailbox_scan (mbox, &msg_total);
for (msgno = 0; msgno < msg_total; msgno++)
@{
if (mailbox_get_header (mbox, msgno, buffer,
sizeof (buffer), &size) != 0)
@{
fprintf (stderr, "header corrupted\n");
exit (EXIT_FAILURE);
@}
header_gvalue (buffer, size, MU_HDR_FROM, from,
sizeof (from), NULL);
header_gvalue (buffer, size, MU_HDR_SUBJECT, subject,
sizeof (subject), NULL);
printf ("%s %s\n", from, subject);
@}
mailbox_close (mbox);
mailbox_destroy (&mbox);
return 0;
@}