Commit 2cfe74a5 2cfe74a504132495b4e124e04c6d33c8aefbfbc5 by Sergey Poznyakoff

Removed

1 parent 74a83b9f
# Makefile
CFLAGS = -g -I../include -Wall -I../lib
LDFLAGS = -g -static
# On QNX
LDLIBS = -lsocket
# On GNU/Linux (if compile with threads)
#LDLIBS = -lpthread
MULIBS = ../lib/.libs/libmailutils.a ../mailbox/.libs/libmailbox.a ../lib/.libs/libmailutils.a
EXES = addr mbox-explode mbox-dates mbox-auth url-parse mbox-check mimetest msg-send muemail
default: $(EXES)
$(EXES): $(MULIBS)
# example of parsing the date fields, prints all the incorrectly
# formatted dates in a mailbox.
bad-dates: mbox-dates
for m in ~/Mail/*; do ./mbox-dates $$m; done | tee bad-dates.out
# addr example and test
addr.test: addr
./addr < Addrs > Addrs.test
@echo "---- There should be no differences! ----"
diff -C5 -u Addrs.good Addrs.test
# url example and test
url.test: url-parse
./url-parse < Urls > Urls.test
@echo "---- There should be no differences! ----"
diff -u Urls.good Urls.test
# mimetest example and test
# TODO
# clean and empty
clean:
rm -f *.o
empty: clean
rm -f $(EXES)
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <mailutils/address.h>
#include <mailutils/debug.h>
#include <mailutils/errno.h>
#include <mailutils/mailbox.h>
#include <mailutils/parse822.h>
#include <mailutils/registrar.h>
#include <mailutils/stream.h>
int
main (int argc, char **argv)
{
mailbox_t mbox;
size_t count = 0;
char *mboxname = argv[1];
int status;
/* Register desired mailbox formats. */
{
list_t bookie;
registrar_get_list (&bookie);
list_append (bookie, path_record);
list_append (bookie, pop_record);
list_append (bookie, imap_record);
}
if ((status = mailbox_create_default (&mbox, mboxname)) != 0)
{
fprintf (stderr, "could not create <%s>: %s\n",
mboxname, mu_errstring (status));
return status;
}
{
mu_debug_t debug;
mailbox_get_debug (mbox, &debug);
mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT);
}
if ((status = mailbox_open (mbox, MU_STREAM_READ)) != 0)
{
fprintf (stderr, "could not open <%s>: %s\n",
mboxname, mu_errstring (status));
mailbox_destroy (&mbox);
exit (1);
}
if ((status = mailbox_messages_count (mbox, &count)) != 0)
{
fprintf (stderr, "could not count <%s>: %s\n",
mboxname, mu_errstring (status));
mailbox_close (mbox);
mailbox_destroy (&mbox);
exit (1);
}
mailbox_close (mbox);
mailbox_destroy (&mbox);
printf("count %d messages in <%s>\n", count, mboxname);
return 0;
}
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <mailutils/address.h>
#include <mailutils/debug.h>
#include <mailutils/errno.h>
#include <mailutils/header.h>
#include <mailutils/mailbox.h>
#include <mailutils/message.h>
#include <mailutils/parse822.h>
#include <mailutils/registrar.h>
#include <mailutils/stream.h>
static const char *
UserAgent (header_t hdr)
{
static char agent[128];
size_t sz;
if (header_get_value (hdr, "User-Agent", agent, sizeof (agent), &sz) == 0
&& sz != 0)
return agent;
if (header_get_value (hdr, "X-Mailer", agent, sizeof (agent), &sz) == 0
&& sz != 0)
return agent;
/* Some MUAs, like Pine, put their name in the Message-Id, so print it as
a last ditch attempt at getting an idea who produced the date. */
if (header_get_value (hdr, "Message-Id", agent, sizeof (agent), &sz) == 0
&& sz != 0)
return agent;
return "unknown";
}
int
main (int argc, char **argv)
{
mailbox_t mbox;
size_t i;
size_t count = 0;
char *mboxname = argv[1];
int status;
int debug = 0;
if (strcmp ("-d", mboxname) == 0)
{
mboxname = argv[2];
debug = 1;
}
if (mboxname == NULL)
{
printf ("Usage: mbox-dates [-d] <mbox>\n");
exit (1);
}
/* Register desired mailbox formats. */
{
list_t bookie;
registrar_get_list (&bookie);
list_append (bookie, path_record);
list_append (bookie, pop_record);
list_append (bookie, imap_record);
}
if ((status = mailbox_create_default (&mbox, mboxname)) != 0)
{
fprintf (stderr, "could not create <%s>: %s\n",
mboxname, mu_errstring (status));
exit (1);
}
if (debug)
{
mu_debug_t debug;
mailbox_get_debug (mbox, &debug);
mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT);
}
if ((status = mailbox_open (mbox, MU_STREAM_READ)) != 0)
{
fprintf (stderr, "could not open mbox: %s\n", mu_errstring (status));
exit (1);
}
mailbox_messages_count (mbox, &count);
for (i = 1; i <= count; ++i)
{
message_t msg;
header_t hdr;
char date[128];
size_t len = 0;
if ((status = mailbox_get_message (mbox, i, &msg)) != 0 ||
(status = message_get_header (msg, &hdr)) != 0)
{
printf ("%s, msg %d: %s\n", mboxname, i, mu_errstring (status));
continue;
}
if ((status =
header_get_value (hdr, MU_HEADER_DATE, date, sizeof (date),
&len)) != 0)
{
printf ("%s, msg %d: NO DATE (mua? %s)\n",
mboxname, i, UserAgent (hdr));
continue;
}
else
{
const char *s = date;
if (parse822_date_time (&s, s + strlen (s), NULL, NULL))
{
printf ("%s, msg %d: BAD DATE <%s> (mua? %s)\n",
mboxname, i, date, UserAgent (hdr));
continue;
}
}
}
mailbox_close (mbox);
mailbox_destroy (&mbox);
return status;
}
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <mailutils/debug.h>
#include <mailutils/errno.h>
#include <mailutils/list.h>
#include <mailutils/mailbox.h>
#include <mailutils/registrar.h>
#include <mailutils/stream.h>
#include <mailutils/message.h>
int
main (int argc, char **argv)
{
mailbox_t mbox;
size_t msgno;
size_t count = 0;
char *mbox_name = 0;
char *dir_name = 0;
int status;
int debug = 0;
if (strcmp("-d", argv[1]) == 0 && argc == 4)
{
debug = 1;
argc--;
argv[1] = argv[2];
argv[2] = argv[3];
}
if (argc != 3)
{
printf ("usage: mbox-explode <mbox> <directory>\n");
exit (0);
}
mbox_name = argv[1];
dir_name = argv[2];
/* Register the desire formats. */
{
list_t bookie;
registrar_get_list (&bookie);
list_append (bookie, path_record);
list_append (bookie, imap_record);
}
if ((status = mailbox_create_default (&mbox, mbox_name)) != 0)
{
fprintf (stderr, "could not create <%s>: %s\n",
mbox_name, mu_errstring (status));
exit (1);
}
if(debug)
{
mu_debug_t debug;
mailbox_get_debug (mbox, &debug);
mu_debug_set_level (debug, MU_DEBUG_TRACE | MU_DEBUG_PROT);
}
if ((status = mailbox_open (mbox, MU_STREAM_READ)) != 0)
{
fprintf (stderr, "could not open <%s>: %s\n",
mbox_name, mu_errstring (status));
exit (1);
}
mailbox_messages_count (mbox, &count);
if (mkdir (dir_name, 0777) != 0)
{
fprintf (stderr, "mkdir(%s) failed: %s\n", dir_name, strerror (errno));
mailbox_close (mbox);
exit (1);
}
for (msgno = 1; msgno <= count; ++msgno)
{
message_t msg = 0;
size_t nparts = 0;
size_t partno;
if ((status = mailbox_get_message (mbox, msgno, &msg)) != 0)
{
fprintf (stderr, "msg %d: get message failed: %s\n",
msgno, mu_errstring (status));
mailbox_close (mbox);
exit (1);
}
if ((status = message_get_num_parts (msg, &nparts)))
{
fprintf (stderr, "msg %d: get num parts failed: %s\n",
msgno, mu_errstring (status));
mailbox_close (mbox);
exit (1);
}
printf ("msg %03d: %02d parts\n", msgno, nparts);
for (partno = 1; partno <= nparts; partno++)
{
message_t part = 0;
char path[128];
sprintf (path, "%s/m%03d.p%02d", dir_name, msgno, partno);
printf ("msg %03d: part %02d > %s\n", msgno, partno, path);
if ((status = message_get_part (msg, partno, &part)))
{
fprintf (stderr, "msg %d: get part %d failed: %s\n",
msgno, partno, mu_errstring (status));
mailbox_close (mbox);
exit (1);
}
if ((status = message_save_attachment (part, path, 0)))
{
fprintf (stderr, "msg %d part %d: save failed: %s\n",
msgno, partno, mu_errstring (status));
break;
}
}
}
mailbox_close (mbox);
mailbox_destroy (&mbox);
return status;
}