Commit 04196928 04196928f7ddb13bafb2ac844338f18df2a0494c by Alain Magloire

Base on Jakob idea propose an implementation for decode.

	But it is clearly not flexible enough:

	  decode [msgno] [part]
	  ? decode 28 2

	Suppose message 28 is a mime with two part, the second part
	will be decoded and sent to stdout.

	* mail/decode.c: First implementation behind Jakobs idea.
1 parent 490823a9
......@@ -25,6 +25,74 @@
int
mail_decode (int argc, char **argv)
{
fprintf (stderr, "Sorry, the decode function hasn't been implemented yet");
#if 0
fprintf (stderr, "Sorry, the decode function hasn't been implemented yet\n");
return 1;
#else
message_t msg = NULL;
int partno;
int *list = NULL;
int num = util_expand_msglist (argc, argv, &list);
partno = (num >= 2) ? list[1] : 1;
if (mailbox_get_message (mbox, list[0], &msg) == 0)
{
message_t part = NULL;
if (message_get_part (msg, partno, &part) == 0)
{
body_t body = NULL;
header_t hdr = NULL;
stream_t stream = NULL;
stream_t b_stream = NULL;
size_t len = 0;
char *encoding = NULL;
message_get_body (part, &body);
body_get_stream (body, &b_stream);
message_get_header (part, &hdr);
if (header_aget_value (hdr, MU_HEADER_CONTENT_TRANSFER_ENCODING,
&encoding) == 0)
{
size_t lines = 0;
char buffer[512];
off_t off = 0;
size_t n = 0;
FILE *out = ofile;
stream_t d_stream = NULL;
message_lines (part, &lines);
if ((util_find_env("crt"))->set && lines > util_getlines ())
out = popen (getenv("PAGER"), "w");
/* Do I understand this encoding? */
if (*encoding
&& filter_create(&d_stream, b_stream, encoding,
MU_FILTER_DECODE, MU_STREAM_READ) == 0)
stream = d_stream;
else
stream = b_stream;
while (stream_read (stream, buffer, sizeof buffer,
off, &n ) == 0 && n)
{
if (ml_got_interrupt())
{
util_error("\nInterrupt");
break;
}
buffer[n] = '\0';
fprintf (out, "%s", buffer);
off += n;
}
if (d_stream)
stream_destroy (&d_stream, NULL);
if (out != ofile)
pclose (out);
free (encoding);
}
}
}
free (list);
#endif
}
......
......@@ -60,6 +60,7 @@
#include <mailutils/iterator.h>
#include <mailutils/address.h>
#include <mailutils/mutil.h>
#include <mailutils/filter.h>
#include <argcv.h>
#include <getline.h>
......
......@@ -25,7 +25,7 @@ const struct mail_command_entry mail_command_table[] = {
{ "cd", "cd", 0, mail_cd, "cd [directory]" },
{ "ch", "chdir", 0, mail_cd, "ch[dir] directory" },
{ "c", "copy", 0, mail_copy, "c[opy] [[msglist] file]" },
{ "dec", "decode", 0, mail_decode, "dec[ode] ???" },
{ "dec", "decode", 0, mail_decode, "dec[ode] [msgno] [part]" },
{ "d", "delete", 0, mail_delete, "d[elete] [msglist]" },
{ "di", "discard", 0, mail_discard,
"di[scard] [header-field...]" },
......