sfrom.c.texi 1.38 KB
/* sfrom, Simple From */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.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, 0, 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;
@}