summaryrefslogtreecommitdiff
path: root/mu
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-12-08 11:20:51 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2011-12-08 11:36:18 +0200
commit6301266fabab03f0e1dfcab76e7b6fc1e6eda1c6 (patch)
tree53094841f9296cc66affa67df987345b6a055f16 /mu
parent5357fe739bdec1b99abff548098decd4e8c6c5ef (diff)
downloadmailutils-6301266fabab03f0e1dfcab76e7b6fc1e6eda1c6.tar.gz
mailutils-6301266fabab03f0e1dfcab76e7b6fc1e6eda1c6.tar.bz2
imap client: implement CREATE and APPEND. Fix APPEND in imap4d.
* imap4d/append.c (imap4d_append0): Use mu_message_from_stream_with_envelope with crafted envelope. The effect is that the envelope of the message always reflects the actual sender, as deduced from the header (X-Envelope-Sender, Sender, From, in that order) and the date given with the APPEND command (or current date/time, if not given). * imap4d/tests/append00.at: Reflect changes in the envelope. * imap4d/tests/append01.at: Likewise. * imap4d/io.c (io_format_completion_response): Call imap4d_sync to emit eventual non-tagged responses before the tagged one. * include/mailutils/envelope.h (mu_envelope_set_destroy): New proto. * include/mailutils/header.h (MU_HEADER_SENDER): Remove duplicate define. * include/mailutils/imap.h (mu_imap_mailbox_create) (mu_imap_append_stream_size,mu_imap_append_stream) (mu_imap_append_message,mu_imapio_send_flags) (mu_imapio_send_time): New protos. * include/mailutils/imapio.h (mu_imapio_send_literal): Remove proto. (mu_imapio_send_literal_string) (mu_imapio_send_literal_stream): New protos. * include/mailutils/message.h (mu_message_from_stream_with_envelope): New proto. * include/mailutils/sys/imap.h (MU_IMAP_CLIENT_APPEND_RX): New state. * include/mailutils/sys/message_stream.h (_mu_message_stream) <envelope>: Rename to envelope_string. <construct_envelope>: New member. * libmailutils/imapio/literal.c: Remove. * libmailutils/imapio/litstream.c: New file. * libmailutils/imapio/litstring.c: New file. * libmailutils/imapio/time.c: New file. * libmailutils/imapio/Makefile.am: Add new files. * libmailutils/imapio/flags.c (mu_imapio_send_flags): New function. * libmailutils/imapio/qstring.c (mu_imapio_send_qstring_unfold): Use mu_imapio_send_literal_string. * libmailutils/mailbox/envelope.c (mu_envelope_set_destroy): New function. * libmailutils/stream/message_stream.c (mu_message_from_stream_with_envelope): New function. (mu_stream_to_message): Rewrite as an alternative entry point to the above. * libproto/imap/Makefile.am: Add new files. * libproto/imap/appmsg.c: New file. * libproto/imap/appstr.c: New file. * libproto/imap/appstrsiz.c: New file. * libproto/imap/mbcreate.c: New file. * mu/imap.c: Implement create and append.
Diffstat (limited to 'mu')
-rw-r--r--mu/imap.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/mu/imap.c b/mu/imap.c
index 54680581b..26a3401d9 100644
--- a/mu/imap.c
+++ b/mu/imap.c
@@ -808,6 +808,93 @@ com_expunge (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
return 0;
}
+static int
+com_create (int argc, char **argv)
+{
+ int status = mu_imap_mailbox_create (imap, argv[1]);
+ if (status)
+ report_failure ("create", status);
+ return 0;
+}
+
+static int
+com_append (int argc, char **argv)
+{
+ struct tm tmbuf, *tm = NULL;
+ struct mu_timezone tzbuf, *tz = NULL;
+ int flags = 0;
+ mu_stream_t stream;
+ int rc, i;
+
+ for (i = 1; i < argc; i++)
+ {
+ if (strcmp (argv[i], "-time") == 0)
+ {
+ char *p;
+
+ if (++i == argc)
+ {
+ mu_error (_("-time requires argument"));
+ return 0;
+ }
+ rc = mu_scan_datetime (argv[i], MU_DATETIME_INTERNALDATE,
+ &tmbuf, &tzbuf, &p);
+ if (rc || *p)
+ {
+ mu_error (_("cannot parse time"));
+ return 0;
+ }
+ tm = &tmbuf;
+ tz = &tzbuf;
+ }
+ else if (strcmp (argv[i], "-flag") == 0)
+ {
+ if (++i == argc)
+ {
+ mu_error (_("-flag requires argument"));
+ return 0;
+ }
+ if (mu_imap_flag_to_attribute (argv[i], &flags))
+ {
+ mu_error (_("unrecognized flag: %s"), argv[i]);
+ return 0;
+ }
+ }
+ else if (strcmp (argv[i], "--") == 0)
+ {
+ i++;
+ break;
+ }
+ else if (argv[i][0] == '-')
+ {
+ mu_error (_("unrecognized option: %s"), argv[i]);
+ return 0;
+ }
+ else
+ break;
+ }
+
+ if (argc - i != 2)
+ {
+ mu_error (_("wrong number of arguments"));
+ return 0;
+ }
+
+ rc = mu_file_stream_create (&stream, argv[i + 1],
+ MU_STREAM_READ|MU_STREAM_SEEK);
+ if (rc)
+ {
+ mu_error (_("cannot open file %s: %s"), argv[i + 1], mu_strerror (rc));
+ return 0;
+ }
+
+ rc = mu_imap_append_stream (imap, argv[i], flags, tm, tz, stream);
+ mu_stream_unref (stream);
+ if (rc)
+ report_failure ("append", rc);
+ return 0;
+}
+
struct mutool_command imap_comtab[] = {
{ "capability", 1, -1, 0,
com_capability,
@@ -887,6 +974,14 @@ struct mutool_command imap_comtab[] = {
com_expunge,
NULL,
N_("permanently remove messages marked for deletion") },
+ { "create", 2, 2, 0,
+ com_create,
+ N_("MAILBOX"),
+ N_("create new mailbox") },
+ { "append", 3, -1, 0,
+ com_append,
+ N_("[-time DATETIME] [-flag FLAG] MAILBOX FILE"),
+ N_("append message text from FILE to MAILBOX") },
{ "quit", 1, 1, 0,
com_logout,
NULL,

Return to:

Send suggestions and report system problems to the System administrator.