(imap4d_append0): Simplified a lot.
Showing
1 changed file
with
46 additions
and
32 deletions
... | @@ -58,27 +58,41 @@ imap4d_append (struct imap4d_command *command, char *arg) | ... | @@ -58,27 +58,41 @@ imap4d_append (struct imap4d_command *command, char *arg) |
58 | return util_finish (command, RESP_NO, "[TRYCREATE] failed"); | 58 | return util_finish (command, RESP_NO, "[TRYCREATE] failed"); |
59 | } | 59 | } |
60 | 60 | ||
61 | static int | ||
62 | _append_date (envelope_t envelope, char *buf, size_t len, size_t *pnwrite) | ||
63 | { | ||
64 | message_t msg = envelope_get_owner (envelope); | ||
65 | struct tm **tm = message_get_owner (msg); | ||
66 | |||
67 | strftime (buf, len, "%a %b %d %H:%M:%S %Y", *tm); | ||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | static int | ||
72 | _append_sender (envelope_t envelope, char *buf, size_t len, size_t *pnwrite) | ||
73 | { | ||
74 | strncpy (buf, "GNU-imap4d", len); | ||
75 | return 0; | ||
76 | } | ||
77 | |||
61 | int | 78 | int |
62 | imap4d_append0 (mailbox_t mbox, int flags, char *text) | 79 | imap4d_append0 (mailbox_t mbox, int flags, char *text) |
63 | { | 80 | { |
64 | mailbox_t tmp; | ||
65 | stream_t stream; | 81 | stream_t stream; |
66 | int rc = 0; | 82 | int rc = 0; |
67 | size_t len = 0; | 83 | size_t len = 0; |
68 | message_t msg; | 84 | message_t msg = 0; |
69 | struct tm *tm; | 85 | struct tm *tm; |
70 | time_t t; | 86 | time_t t; |
71 | char date[80]; | 87 | envelope_t env; |
72 | 88 | ||
73 | if (mailbox_create (&tmp, "/dev/null")) | 89 | if (message_create (&msg, &tm)) |
74 | return 1; | ||
75 | if (mailbox_open (tmp, MU_STREAM_READ) != 0) | ||
76 | return 1; | 90 | return 1; |
77 | 91 | ||
78 | if (memory_stream_create (&stream, 0, MU_STREAM_RDWR) | 92 | if (memory_stream_create (&stream, 0, MU_STREAM_RDWR) |
79 | || stream_open (stream)) | 93 | || stream_open (stream)) |
80 | { | 94 | { |
81 | mailbox_close (tmp); | 95 | message_destroy (&msg, &tm); |
82 | return 1; | 96 | return 1; |
83 | } | 97 | } |
84 | 98 | ||
... | @@ -98,34 +112,34 @@ imap4d_append0 (mailbox_t mbox, int flags, char *text) | ... | @@ -98,34 +112,34 @@ imap4d_append0 (mailbox_t mbox, int flags, char *text) |
98 | time(&t); | 112 | time(&t); |
99 | } | 113 | } |
100 | tm = gmtime(&t); | 114 | tm = gmtime(&t); |
101 | strftime (date, sizeof (date), | 115 | |
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); | 116 | stream_write (stream, text, strlen (text), len, &len); |
117 | message_set_stream (msg, stream, &tm); | ||
107 | 118 | ||
108 | mailbox_set_stream (tmp, stream); | 119 | envelope_create (&env, msg); |
109 | mailbox_messages_count (tmp, &len); | 120 | envelope_set_date (env, _append_date, msg); |
110 | if (len == 1) | 121 | envelope_set_sender (env, _append_sender, msg); |
122 | message_set_envelope (msg, env, &tm); | ||
123 | rc = mailbox_append_message (mbox, msg); | ||
124 | if (rc == 0 && flags) | ||
111 | { | 125 | { |
112 | mailbox_get_message (tmp, 1, &msg); | 126 | size_t num = 0; |
113 | mailbox_append_message (mbox, msg); | 127 | attribute_t attr = NULL; |
114 | if (flags) | 128 | mailbox_messages_count (mbox, &num); |
115 | { | 129 | mailbox_get_message (mbox, num, &msg); |
116 | size_t num = 0; | 130 | message_get_attribute (msg, &attr); |
117 | attribute_t attr = NULL; | 131 | attribute_set_flags (attr, flags); |
118 | mailbox_messages_count (mbox, &num); | ||
119 | mailbox_get_message (mbox, num, &msg); | ||
120 | message_get_attribute (msg, &attr); | ||
121 | attribute_set_flags (attr, flags); | ||
122 | } | ||
123 | } | 132 | } |
124 | else | 133 | |
125 | rc = 1; | 134 | message_destroy (&msg, &tm); |
126 | |||
127 | mailbox_close (tmp); | ||
128 | mailbox_destroy (&tmp); | ||
129 | return rc; | 135 | return rc; |
130 | } | 136 | } |
131 | 137 | ||
138 | int | ||
139 | wd() | ||
140 | { | ||
141 | volatile int _s = 0; | ||
142 | while (!_s) | ||
143 | ; | ||
144 | } | ||
145 | ... | ... |
-
Please register or sign in to post a comment