Commit d95188f6 d95188f6ff2624b1d10c4f3e95e1e818ddb285bc by Sergey Poznyakoff

(imap4d_append0): Simplified a lot.

1 parent 1f6860f3
...@@ -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,20 +112,16 @@ imap4d_append0 (mailbox_t mbox, int flags, char *text) ...@@ -98,20 +112,16 @@ 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),
102 "From GNU-imap4d %a %b %e %H:%M:%S %Y%n",
103 tm);
104 115
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);
107 117 message_set_stream (msg, stream, &tm);
108 mailbox_set_stream (tmp, stream); 118
109 mailbox_messages_count (tmp, &len); 119 envelope_create (&env, msg);
110 if (len == 1) 120 envelope_set_date (env, _append_date, msg);
111 { 121 envelope_set_sender (env, _append_sender, msg);
112 mailbox_get_message (tmp, 1, &msg); 122 message_set_envelope (msg, env, &tm);
113 mailbox_append_message (mbox, msg); 123 rc = mailbox_append_message (mbox, msg);
114 if (flags) 124 if (rc == 0 && flags)
115 { 125 {
116 size_t num = 0; 126 size_t num = 0;
117 attribute_t attr = NULL; 127 attribute_t attr = NULL;
...@@ -120,12 +130,16 @@ imap4d_append0 (mailbox_t mbox, int flags, char *text) ...@@ -120,12 +130,16 @@ imap4d_append0 (mailbox_t mbox, int flags, char *text)
120 message_get_attribute (msg, &attr); 130 message_get_attribute (msg, &attr);
121 attribute_set_flags (attr, flags); 131 attribute_set_flags (attr, flags);
122 } 132 }
123 }
124 else
125 rc = 1;
126 133
127 mailbox_close (tmp); 134 message_destroy (&msg, &tm);
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
......