implemented. See ChangeLog
Showing
1 changed file
with
108 additions
and
5 deletions
... | @@ -17,14 +17,117 @@ | ... | @@ -17,14 +17,117 @@ |
17 | 17 | ||
18 | #include "imap4d.h" | 18 | #include "imap4d.h" |
19 | 19 | ||
20 | /* | 20 | /* APPEND mbox [(flags)] [date_time] message_literal */ |
21 | * | ||
22 | */ | ||
23 | |||
24 | int | 21 | int |
25 | imap4d_append (struct imap4d_command *command, char *arg) | 22 | imap4d_append (struct imap4d_command *command, char *arg) |
26 | { | 23 | { |
24 | char *sp; | ||
25 | char *mboxname; | ||
26 | char *attr_str; | ||
27 | int flags = 0; | ||
28 | mailbox_t dest_mbox = NULL; | ||
29 | int status; | ||
30 | |||
27 | if (! (command->states & state)) | 31 | if (! (command->states & state)) |
28 | return util_finish (command, RESP_BAD, "Wrong state"); | 32 | return util_finish (command, RESP_BAD, "Wrong state"); |
29 | return util_finish (command, RESP_NO, "Not implemented"); | 33 | |
34 | mboxname = util_getword (arg, &sp); | ||
35 | if (!mboxname) | ||
36 | return util_finish (command, RESP_BAD, "Too few arguments"); | ||
37 | |||
38 | if (*sp == '(' && util_parse_attributes (sp+1, &sp, &flags)) | ||
39 | return util_finish (command, RESP_BAD, "Missing closing parenthesis"); | ||
40 | |||
41 | mboxname = namespace_getfullpath (mboxname, "/"); | ||
42 | if (!mboxname) | ||
43 | return util_finish (command, RESP_NO, "Couldn't open mailbox"); | ||
44 | |||
45 | status = mailbox_create_default (&dest_mbox, mboxname); | ||
46 | if (status == 0) | ||
47 | { | ||
48 | /* It SHOULD NOT automatifcllly create the mailbox. */ | ||
49 | status = mailbox_open (dest_mbox, MU_STREAM_RDWR); | ||
50 | if (status == 0) | ||
51 | { | ||
52 | status = imap4d_append0 (dest_mbox, flags, sp); | ||
53 | mailbox_close (dest_mbox); | ||
54 | } | ||
55 | mailbox_destroy (&dest_mbox); | ||
56 | } | ||
57 | |||
58 | free (mboxname); | ||
59 | if (status == 0) | ||
60 | return util_finish (command, RESP_OK, "Completed"); | ||
61 | |||
62 | return util_finish (command, RESP_NO, "[TRYCREATE] failed"); | ||
30 | } | 63 | } |
64 | |||
65 | int | ||
66 | imap4d_append0 (mailbox_t mbox, int flags, char *text) | ||
67 | { | ||
68 | mailbox_t tmp; | ||
69 | stream_t stream; | ||
70 | int rc = 0; | ||
71 | size_t len = 0; | ||
72 | message_t msg; | ||
73 | struct tm *tm; | ||
74 | time_t t; | ||
75 | char date[80]; | ||
76 | |||
77 | if (mailbox_create (&tmp, "/dev/null")) | ||
78 | return 1; | ||
79 | if (mailbox_open (tmp, MU_STREAM_READ) != 0) | ||
80 | return 1; | ||
81 | |||
82 | if (memory_stream_create (&stream)) | ||
83 | { | ||
84 | mailbox_close (tmp); | ||
85 | return 1; | ||
86 | } | ||
87 | |||
88 | /* If a date_time is specified, the internal date SHOULD be set in the | ||
89 | resulting message; otherwise, the internal date of the resulting | ||
90 | message is set to the current date and time by default. */ | ||
91 | if (util_parse_internal_date0 (text, &t, &text) == 0) | ||
92 | { | ||
93 | while (*text && isspace(*text)) | ||
94 | text++; | ||
95 | } | ||
96 | else | ||
97 | { | ||
98 | time(&t); | ||
99 | } | ||
100 | tm = gmtime(&t); | ||
101 | strftime (date, sizeof (date), | ||
102 | "From GNU-imap4d %a %b %e %H:%M:%S %Y%n", | ||
103 | tm); | ||
104 | |||
105 | stream_write (stream, date, strlen (date), 0, &len); | ||
106 | stream_write (stream, text, strlen (text), len, &len); | ||
107 | |||
108 | mailbox_destroy_folder (tmp); | ||
109 | mailbox_set_stream (tmp, stream); | ||
110 | mailbox_messages_count (tmp, &len); | ||
111 | if (len == 1) | ||
112 | { | ||
113 | mailbox_get_message (tmp, 1, &msg); | ||
114 | mailbox_append_message (mbox, msg); | ||
115 | if (flags) | ||
116 | { | ||
117 | size_t num = 0; | ||
118 | attribute_t attr = NULL; | ||
119 | mailbox_messages_count (mbox, &num); | ||
120 | mailbox_get_message (mbox, num, &msg); | ||
121 | message_get_attribute (msg, &attr); | ||
122 | attribute_set_flags (attr, flags); | ||
123 | } | ||
124 | } | ||
125 | else | ||
126 | rc = 1; | ||
127 | |||
128 | mailbox_close (tmp); | ||
129 | mailbox_destroy (&tmp); | ||
130 | return rc; | ||
131 | } | ||
132 | |||
133 | ... | ... |
-
Please register or sign in to post a comment