~jelmer/ubuntu/natty/evolution-mapi/513394-recurring-events

« back to all changes in this revision

Viewing changes to src/camel/camel-mapi-utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2010-04-08 14:58:05 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20100408145805-5wtcvoulqxh409tx
Tags: 0.28.3-0ubuntu1
New upstream bugfix release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
 
80
80
        /* this memory should be freed somewhere, perhaps in the existing
81
81
         * exchange_mapi_util_free_recipient_list() */
82
 
        recipient->in.req_lpProps = g_new0 (struct SPropValue, 2);
83
82
        recipient->in.req_cValues = 2;
 
83
        recipient->in.req_lpProps = g_new0 (struct SPropValue, recipient->in.req_cValues + 1);
84
84
 
85
85
        set_SPropValue_proptag (&(recipient->in.req_lpProps[0]), PR_RECIPIENT_TYPE, (const void *) &type);
86
86
 
88
88
        set_SPropValue_proptag (&(recipient->in.req_lpProps[1]), PR_SEND_INTERNET_ENCODING, (const void *)&val);
89
89
 
90
90
        /* External recipient properties - set them only when the recipient is unresolved */
91
 
        recipient->in.ext_lpProps = g_new0 (struct SPropValue, 7);
92
91
        recipient->in.ext_cValues = 7;
 
92
        recipient->in.ext_lpProps = g_new0 (struct SPropValue, recipient->in.ext_cValues + 1);
93
93
 
94
94
        val = DT_MAILUSER;
95
95
        set_SPropValue_proptag (&(recipient->in.ext_lpProps[0]), PR_DISPLAY_TYPE, (const void *)&val);
131
131
mapi_item_set_body_stream (MapiItem *item, CamelStream *body, MapiItemPartType part_type)
132
132
{
133
133
        guint8 *buf = g_new0 (guint8 , STREAM_SIZE);
134
 
        guint32 read_size = 0;
 
134
        guint32 read_size = 0, i;
135
135
        ExchangeMAPIStream *stream = g_new0 (ExchangeMAPIStream, 1);
 
136
        gboolean contains_only_7bit = TRUE, is_null_terminated = FALSE;
136
137
 
137
138
        camel_seekable_stream_seek((CamelSeekableStream *)body, 0, CAMEL_STREAM_SET);
138
139
 
139
140
        stream->value = g_byte_array_new ();
140
141
 
141
 
        while((read_size = camel_stream_read(body, (char *)buf, STREAM_SIZE))){
142
 
                if (read_size == -1) 
143
 
                        return;
144
 
 
 
142
        while (read_size = camel_stream_read (body, (char *)buf, STREAM_SIZE), read_size > 0){
145
143
                stream->value = g_byte_array_append (stream->value, buf, read_size);
 
144
 
 
145
                is_null_terminated = buf [read_size - 1] == 0;
 
146
 
 
147
                for (i = 0; i < read_size && contains_only_7bit; i++) {
 
148
                        contains_only_7bit = buf[i] < 128;
 
149
                }
146
150
        }
147
151
 
 
152
        g_free (buf);
 
153
 
148
154
        switch (part_type) {
149
155
        case PART_TYPE_TEXT_HTML :
150
156
                stream->proptag = PR_HTML;
154
160
                break;
155
161
        }
156
162
 
157
 
        if (stream->value->len < MAX_READ_SIZE)
 
163
        if (stream->value->len < MAX_READ_SIZE && contains_only_7bit) {
 
164
                if (!is_null_terminated)
 
165
                        g_byte_array_append (stream->value, (const guint8 *)"", 1);
 
166
 
158
167
                item->msg.body_parts = g_slist_append (item->msg.body_parts, stream);
159
 
        else
 
168
        } else {
 
169
                gsize written = 0;
 
170
                gchar *in_unicode;
 
171
 
 
172
                if (is_null_terminated)
 
173
                        stream->value->len--;
 
174
 
 
175
                /* convert to unicode, because stream is supposed to be in it */
 
176
                in_unicode = g_convert ((const gchar *)stream->value->data, stream->value->len, "UTF-16", "UTF-8", NULL, &written, NULL);
 
177
                if (in_unicode && written > 0) {
 
178
                        g_byte_array_set_size (stream->value, 0);
 
179
                        g_byte_array_append (stream->value, (const guint8 *) in_unicode, written);
 
180
 
 
181
                        /* null-terminated unicode string */
 
182
                        g_byte_array_append (stream->value, (const guint8 *)"", 1);
 
183
                        g_byte_array_append (stream->value, (const guint8 *)"", 1);
 
184
                }
 
185
                g_free (in_unicode);
 
186
 
160
187
                item->generic_streams = g_slist_append (item->generic_streams, stream);
 
188
        }
161
189
 
162
190
}
163
191
 
167
195
        guint8 *buf = g_new0 (guint8 , STREAM_SIZE);
168
196
        const gchar *content_id = NULL;
169
197
        guint32 read_size, flag, i = 0;
 
198
        CamelContentType *content_type;
170
199
 
171
200
        ExchangeMAPIAttachment *item_attach;
172
201
        ExchangeMAPIStream *stream; 
175
204
        
176
205
        item_attach = g_new0 (ExchangeMAPIAttachment, 1);
177
206
 
178
 
        item_attach->lpProps = g_new0 (struct SPropValue, 5);
 
207
        item_attach->lpProps = g_new0 (struct SPropValue, 6 + 1);
179
208
 
180
209
        flag = ATTACH_BY_VALUE; 
181
210
        set_SPropValue_proptag(&(item_attach->lpProps[i++]), PR_ATTACH_METHOD, (const void *) (&flag));
206
235
                                       (const void *) g_strdup(content_id));
207
236
        }
208
237
 
 
238
        content_type  = camel_mime_part_get_content_type (part);
 
239
        if (content_type) {
 
240
                gchar *ct = camel_content_type_simple (content_type);
 
241
                if (ct) {
 
242
                        set_SPropValue_proptag (&(item_attach->lpProps[i++]), 
 
243
                                        PR_ATTACH_MIME_TAG,
 
244
                                        (const void *) ct);
 
245
                }
 
246
        }
 
247
 
209
248
        item_attach->cValues = i;
210
249
 
211
250
        stream = g_new0 (ExchangeMAPIStream, 1);
213
252
        stream->value = g_byte_array_new ();
214
253
 
215
254
        camel_seekable_stream_seek((CamelSeekableStream *)content_stream, 0, CAMEL_STREAM_SET);
216
 
        while((read_size = camel_stream_read(content_stream, (char *)buf, STREAM_SIZE))){
 
255
        while (read_size = camel_stream_read(content_stream, (char *)buf, STREAM_SIZE), read_size > 0) {
217
256
                stream->value = g_byte_array_append (stream->value, buf, read_size);
218
257
        }
219
258
 
224
263
}
225
264
 
226
265
static gboolean 
227
 
mapi_do_multipart(CamelMultipart *mp, MapiItem *item)
 
266
mapi_do_multipart (CamelMultipart *mp, MapiItem *item, gboolean *is_first)
228
267
{
229
268
        CamelDataWrapper *dw;
230
269
        CamelStream *content_stream;
236
275
        const gchar *content_id;
237
276
        gint content_size;
238
277
 
 
278
        g_return_val_if_fail (is_first != NULL, FALSE);
 
279
 
239
280
        n_part = camel_multipart_get_number(mp);
240
281
        for (i_part = 0; i_part < n_part; i_part++) {
241
282
                /* getting part */
243
284
                dw = camel_medium_get_content_object (CAMEL_MEDIUM (part));
244
285
                if (CAMEL_IS_MULTIPART(dw)) {
245
286
                        /* recursive */
246
 
                        if (!mapi_do_multipart(CAMEL_MULTIPART(dw), item))
 
287
                        if (!mapi_do_multipart (CAMEL_MULTIPART (dw), item, is_first))
247
288
                                return FALSE;
248
289
                        continue ;
249
290
                }
252
293
 
253
294
                content_stream = camel_stream_mem_new();
254
295
                content_size = camel_data_wrapper_decode_to_stream (dw, (CamelStream *) content_stream);
255
 
                camel_stream_write ((CamelStream *) content_stream, "", 1);
256
296
 
257
297
                camel_seekable_stream_seek((CamelSeekableStream *)content_stream, 0, CAMEL_STREAM_SET);
258
298
 
261
301
                
262
302
                type = camel_mime_part_get_content_type(part);
263
303
 
264
 
                if (i_part == 0 && camel_content_type_is (type, "text", "plain")) {
 
304
                if (i_part == 0 && (*is_first) && camel_content_type_is (type, "text", "plain")) {
265
305
                        mapi_item_set_body_stream (item, content_stream, PART_TYPE_PLAIN_TEXT);
 
306
                        *is_first = FALSE;
266
307
                } else if (camel_content_type_is (type, "text", "html")) {
267
308
                        mapi_item_set_body_stream (item, content_stream, PART_TYPE_TEXT_HTML);
268
309
                } else {
330
371
        multipart = (CamelMultipart *)camel_medium_get_content_object (CAMEL_MEDIUM (message));
331
372
 
332
373
        if (CAMEL_IS_MULTIPART(multipart)) {
333
 
                if (mapi_do_multipart(CAMEL_MULTIPART(multipart), item))
 
374
                gboolean is_first = TRUE;
 
375
                if (!mapi_do_multipart (CAMEL_MULTIPART(multipart), item, &is_first))
334
376
                        printf("camel message multi part error\n"); 
335
377
        } else {
336
378
                dw = camel_medium_get_content_object (CAMEL_MEDIUM (message));
339
381
                        content_type = camel_content_type_simple (type);
340
382
 
341
383
                        content_stream = (CamelStream *)camel_stream_mem_new();
342
 
                        content_size = camel_data_wrapper_write_to_stream(dw, (CamelStream *)content_stream);
343
 
                        camel_stream_write ((CamelStream *) content_stream, "", 1);
 
384
                        content_size = camel_data_wrapper_decode_to_stream(dw, (CamelStream *)content_stream);
344
385
 
345
386
                        mapi_item_set_body_stream (item, content_stream, PART_TYPE_PLAIN_TEXT);
346
387
                }
360
401
        GSList *l;
361
402
        bool *send_rich_info = g_new0 (bool, 1);
362
403
        uint32_t *msgflag = g_new0 (uint32_t, 1);
 
404
        uint32_t *cpid = g_new0 (uint32_t, 1);
363
405
        int i=0;
364
406
 
365
 
        props = g_new0 (struct SPropValue, 10);
 
407
        props = g_new0 (struct SPropValue, 11 + 1);
366
408
 
 
409
        *cpid = 65001; /* UTF8 */
 
410
        set_SPropValue_proptag(&props[i++], PR_INTERNET_CPID, cpid);
367
411
        set_SPropValue_proptag(&props[i++], PR_SUBJECT_UNICODE, g_strdup (item->header.subject));
368
412
        set_SPropValue_proptag(&props[i++], PR_CONVERSATION_TOPIC_UNICODE, g_strdup (item->header.subject));
369
413
        set_SPropValue_proptag(&props[i++], PR_NORMALIZED_SUBJECT_UNICODE, g_strdup (item->header.subject));