Throw exceptions on errors.
Showing
1 changed file
with
247 additions
and
63 deletions
... | @@ -195,34 +195,51 @@ SCM_DEFINE (scm_mu_message_copy, "mu-message-copy", 1, 0, 0, | ... | @@ -195,34 +195,51 @@ SCM_DEFINE (scm_mu_message_copy, "mu-message-copy", 1, 0, 0, |
195 | mu_stream_t in = NULL, out = NULL; | 195 | mu_stream_t in = NULL, out = NULL; |
196 | char buffer[512]; | 196 | char buffer[512]; |
197 | size_t off, n; | 197 | size_t off, n; |
198 | int status; | ||
198 | 199 | ||
199 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 200 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
200 | msg = mu_scm_message_get (MESG); | 201 | msg = mu_scm_message_get (MESG); |
201 | 202 | ||
202 | if (mu_message_get_stream (msg, &in)) | 203 | status = mu_message_get_stream (msg, &in); |
203 | return SCM_BOOL_F; | 204 | if (status) |
205 | mu_scm_error (FUNC_NAME, status, | ||
206 | "Cannot get input stream from message ~A", | ||
207 | scm_list_1 (MESG)); | ||
204 | 208 | ||
205 | if (mu_message_create (&newmsg, NULL)) | 209 | status = mu_message_create (&newmsg, NULL); |
206 | return SCM_BOOL_F; | 210 | if (status) |
211 | mu_scm_error (FUNC_NAME, status, | ||
212 | "Cannot create message", SCM_BOOL_F); | ||
207 | 213 | ||
208 | if (mu_message_get_stream (newmsg, &out)) | 214 | status = mu_message_get_stream (newmsg, &out); |
215 | if (status) | ||
209 | { | 216 | { |
210 | mu_message_destroy (&newmsg, NULL); | 217 | mu_message_destroy (&newmsg, NULL); |
211 | return SCM_BOOL_F; | 218 | mu_scm_error (FUNC_NAME, status, |
219 | "Cannot get output stream", SCM_BOOL_F); | ||
212 | } | 220 | } |
213 | 221 | ||
214 | off = 0; | 222 | off = 0; |
215 | while (mu_stream_read (in, buffer, sizeof (buffer) - 1, off, &n) == 0 | 223 | while ((status = mu_stream_read (in, buffer, sizeof (buffer) - 1, off, &n)) |
224 | == 0 | ||
216 | && n != 0) | 225 | && n != 0) |
217 | { | 226 | { |
218 | int wr; | 227 | int wr; |
228 | int rc; | ||
229 | |||
230 | rc = mu_stream_write (out, buffer, n, off, &wr); | ||
231 | if (rc) | ||
232 | { | ||
233 | mu_message_destroy (&newmsg, NULL); | ||
234 | mu_scm_error (FUNC_NAME, rc, "Error writing to stream", SCM_BOOL_F); | ||
235 | } | ||
219 | 236 | ||
220 | mu_stream_write (out, buffer, n, off, &wr); | ||
221 | off += n; | 237 | off += n; |
222 | if (wr != n) | 238 | if (wr != n) |
223 | { | 239 | { |
224 | mu_message_destroy (&newmsg, NULL); | 240 | mu_message_destroy (&newmsg, NULL); |
225 | return SCM_BOOL_F; | 241 | mu_scm_error (FUNC_NAME, rc, "Error writing to stream: Short write", |
242 | SCM_BOOL_F); | ||
226 | } | 243 | } |
227 | } | 244 | } |
228 | 245 | ||
... | @@ -255,6 +272,7 @@ SCM_DEFINE (scm_mu_message_set_header, "mu-message-set-header", 3, 1, 0, | ... | @@ -255,6 +272,7 @@ SCM_DEFINE (scm_mu_message_set_header, "mu-message-set-header", 3, 1, 0, |
255 | mu_message_t msg; | 272 | mu_message_t msg; |
256 | mu_header_t hdr; | 273 | mu_header_t hdr; |
257 | int replace = 0; | 274 | int replace = 0; |
275 | int status; | ||
258 | 276 | ||
259 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 277 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
260 | msg = mu_scm_message_get (MESG); | 278 | msg = mu_scm_message_get (MESG); |
... | @@ -269,9 +287,19 @@ SCM_DEFINE (scm_mu_message_set_header, "mu-message-set-header", 3, 1, 0, | ... | @@ -269,9 +287,19 @@ SCM_DEFINE (scm_mu_message_set_header, "mu-message-set-header", 3, 1, 0, |
269 | replace = REPLACE == SCM_BOOL_T; | 287 | replace = REPLACE == SCM_BOOL_T; |
270 | } | 288 | } |
271 | 289 | ||
272 | mu_message_get_header (msg, &hdr); | 290 | status = mu_message_get_header (msg, &hdr); |
273 | mu_header_set_value (hdr, scm_i_string_chars (HEADER), scm_i_string_chars (VALUE), | 291 | if (status) |
292 | mu_scm_error (FUNC_NAME, status, | ||
293 | "Cannot get message headers", SCM_BOOL_F); | ||
294 | |||
295 | status = mu_header_set_value (hdr, scm_i_string_chars (HEADER), | ||
296 | scm_i_string_chars (VALUE), | ||
274 | replace); | 297 | replace); |
298 | if (status) | ||
299 | mu_scm_error (FUNC_NAME, status, | ||
300 | "Cannot set header \"~A: ~A\" in message ~A", | ||
301 | scm_list_3 (HEADER, VALUE, MESG)); | ||
302 | |||
275 | return SCM_UNSPECIFIED; | 303 | return SCM_UNSPECIFIED; |
276 | } | 304 | } |
277 | #undef FUNC_NAME | 305 | #undef FUNC_NAME |
... | @@ -297,9 +325,16 @@ SCM_DEFINE (scm_mu_message_get_lines, "mu-message-get-lines", 1, 0, 0, | ... | @@ -297,9 +325,16 @@ SCM_DEFINE (scm_mu_message_get_lines, "mu-message-get-lines", 1, 0, 0, |
297 | { | 325 | { |
298 | mu_message_t msg; | 326 | mu_message_t msg; |
299 | size_t lines; | 327 | size_t lines; |
328 | int status; | ||
329 | |||
300 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 330 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
301 | msg = mu_scm_message_get (MESG); | 331 | msg = mu_scm_message_get (MESG); |
302 | mu_message_lines (msg, &lines); | 332 | status = mu_message_lines (msg, &lines); |
333 | if (status) | ||
334 | mu_scm_error (FUNC_NAME, status, | ||
335 | "Cannot get number of lines in message ~A", | ||
336 | scm_list_1 (MESG)); | ||
337 | |||
303 | return mu_scm_makenum (lines); | 338 | return mu_scm_makenum (lines); |
304 | } | 339 | } |
305 | #undef FUNC_NAME | 340 | #undef FUNC_NAME |
... | @@ -311,16 +346,22 @@ SCM_DEFINE (scm_mu_message_get_sender, "mu-message-get-sender", 1, 0, 0, | ... | @@ -311,16 +346,22 @@ SCM_DEFINE (scm_mu_message_get_sender, "mu-message-get-sender", 1, 0, 0, |
311 | { | 346 | { |
312 | mu_message_t msg; | 347 | mu_message_t msg; |
313 | mu_envelope_t env = NULL; | 348 | mu_envelope_t env = NULL; |
314 | SCM ret = SCM_BOOL_F; | 349 | int status; |
350 | SCM ret; | ||
315 | 351 | ||
316 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 352 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
317 | msg = mu_scm_message_get (MESG); | 353 | msg = mu_scm_message_get (MESG); |
318 | if (mu_message_get_envelope (msg, &env) == 0) | 354 | status = mu_message_get_envelope (msg, &env); |
355 | if (status == 0) | ||
319 | { | 356 | { |
320 | char *p = _get_envelope_sender (env); | 357 | char *p = _get_envelope_sender (env); |
321 | ret = scm_makfrom0str (p); | 358 | ret = scm_makfrom0str (p); |
322 | free (p); | 359 | free (p); |
323 | } | 360 | } |
361 | else | ||
362 | mu_scm_error (FUNC_NAME, status, | ||
363 | "Cannot get envelope of message ~A", | ||
364 | scm_list_1 (MESG)); | ||
324 | return ret; | 365 | return ret; |
325 | } | 366 | } |
326 | #undef FUNC_NAME | 367 | #undef FUNC_NAME |
... | @@ -334,18 +375,36 @@ SCM_DEFINE (scm_mu_message_get_header, "mu-message-get-header", 2, 0, 0, | ... | @@ -334,18 +375,36 @@ SCM_DEFINE (scm_mu_message_get_header, "mu-message-get-header", 2, 0, 0, |
334 | mu_header_t hdr; | 375 | mu_header_t hdr; |
335 | char *value = NULL; | 376 | char *value = NULL; |
336 | const char *header_string; | 377 | const char *header_string; |
337 | SCM ret = SCM_BOOL_F; | 378 | SCM ret; |
379 | int status; | ||
338 | 380 | ||
339 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 381 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
340 | msg = mu_scm_message_get (MESG); | 382 | msg = mu_scm_message_get (MESG); |
341 | SCM_ASSERT (scm_is_string (HEADER), HEADER, SCM_ARG2, FUNC_NAME); | 383 | SCM_ASSERT (scm_is_string (HEADER), HEADER, SCM_ARG2, FUNC_NAME); |
342 | header_string = scm_i_string_chars (HEADER); | 384 | header_string = scm_i_string_chars (HEADER); |
343 | mu_message_get_header (msg, &hdr); | 385 | status = mu_message_get_header (msg, &hdr); |
344 | if (mu_header_aget_value (hdr, header_string, &value) == 0) | 386 | if (status) |
387 | mu_scm_error (FUNC_NAME, status, | ||
388 | "Cannot get message headers", SCM_BOOL_F); | ||
389 | |||
390 | status = mu_header_aget_value (hdr, header_string, &value); | ||
391 | switch (status) | ||
345 | { | 392 | { |
393 | case 0: | ||
346 | ret = scm_makfrom0str (value); | 394 | ret = scm_makfrom0str (value); |
347 | free (value); | 395 | free (value); |
396 | break; | ||
397 | |||
398 | case MU_ERR_NOENT: | ||
399 | ret = SCM_BOOL_F; | ||
400 | break; | ||
401 | |||
402 | default: | ||
403 | mu_scm_error (FUNC_NAME, status, | ||
404 | "Cannot get header ~A from message ~A", | ||
405 | scm_list_2 (HEADER, MESG)); | ||
348 | } | 406 | } |
407 | |||
349 | return ret; | 408 | return ret; |
350 | } | 409 | } |
351 | #undef FUNC_NAME | 410 | #undef FUNC_NAME |
... | @@ -375,6 +434,7 @@ SCM_DEFINE (scm_mu_message_get_header_fields, "mu-message-get-header-fields", 1, | ... | @@ -375,6 +434,7 @@ SCM_DEFINE (scm_mu_message_get_header_fields, "mu-message-get-header-fields", 1, |
375 | mu_header_t hdr = NULL; | 434 | mu_header_t hdr = NULL; |
376 | SCM scm_first = SCM_EOL, scm_last; | 435 | SCM scm_first = SCM_EOL, scm_last; |
377 | SCM headers = SCM_EOL; | 436 | SCM headers = SCM_EOL; |
437 | int status; | ||
378 | 438 | ||
379 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 439 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
380 | msg = mu_scm_message_get (MESG); | 440 | msg = mu_scm_message_get (MESG); |
... | @@ -385,17 +445,33 @@ SCM_DEFINE (scm_mu_message_get_header_fields, "mu-message-get-header-fields", 1, | ... | @@ -385,17 +445,33 @@ SCM_DEFINE (scm_mu_message_get_header_fields, "mu-message-get-header-fields", 1, |
385 | headers = HEADERS; | 445 | headers = HEADERS; |
386 | } | 446 | } |
387 | 447 | ||
388 | mu_message_get_header (msg, &hdr); | 448 | status = mu_message_get_header (msg, &hdr); |
389 | mu_header_get_field_count (hdr, &nfields); | 449 | if (status) |
450 | mu_scm_error (FUNC_NAME, status, | ||
451 | "Cannot get message headers", SCM_BOOL_F); | ||
452 | status = mu_header_get_field_count (hdr, &nfields); | ||
453 | if (status) | ||
454 | mu_scm_error (FUNC_NAME, status, | ||
455 | "Cannot get header field count", SCM_BOOL_F); | ||
456 | |||
390 | for (i = 1; i <= nfields; i++) | 457 | for (i = 1; i <= nfields; i++) |
391 | { | 458 | { |
392 | SCM new_cell, scm_name, scm_value; | 459 | SCM new_cell, scm_name, scm_value; |
393 | char *name, *value; | 460 | char *name, *value; |
394 | 461 | ||
395 | mu_header_aget_field_name (hdr, i, &name); | 462 | status = mu_header_aget_field_name (hdr, i, &name); |
463 | if (status) | ||
464 | mu_scm_error (FUNC_NAME, status, | ||
465 | "Cannot get header field ~A, message ~A", | ||
466 | scm_list_2 (scm_from_size_t (i), MESG)); | ||
467 | |||
396 | if (headers != SCM_EOL && string_sloppy_member (headers, name) == 0) | 468 | if (headers != SCM_EOL && string_sloppy_member (headers, name) == 0) |
397 | continue; | 469 | continue; |
398 | mu_header_aget_field_value (hdr, i, &value); | 470 | status = mu_header_aget_field_value (hdr, i, &value); |
471 | if (status) | ||
472 | mu_scm_error (FUNC_NAME, status, | ||
473 | "Cannot get header value ~A, message ~A", | ||
474 | scm_list_2 (scm_from_size_t (i), MESG)); | ||
399 | 475 | ||
400 | scm_name = scm_makfrom0str (name); | 476 | scm_name = scm_makfrom0str (name); |
401 | scm_value = scm_makfrom0str (value); | 477 | scm_value = scm_makfrom0str (value); |
... | @@ -433,6 +509,7 @@ SCM_DEFINE (scm_mu_message_set_header_fields, "mu-message-set-header-fields", 2, | ... | @@ -433,6 +509,7 @@ SCM_DEFINE (scm_mu_message_set_header_fields, "mu-message-set-header-fields", 2, |
433 | mu_header_t hdr; | 509 | mu_header_t hdr; |
434 | SCM list; | 510 | SCM list; |
435 | int replace = 0; | 511 | int replace = 0; |
512 | int status; | ||
436 | 513 | ||
437 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 514 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
438 | msg = mu_scm_message_get (MESG); | 515 | msg = mu_scm_message_get (MESG); |
... | @@ -446,19 +523,30 @@ SCM_DEFINE (scm_mu_message_set_header_fields, "mu-message-set-header-fields", 2, | ... | @@ -446,19 +523,30 @@ SCM_DEFINE (scm_mu_message_set_header_fields, "mu-message-set-header-fields", 2, |
446 | replace = REPLACE == SCM_BOOL_T; | 523 | replace = REPLACE == SCM_BOOL_T; |
447 | } | 524 | } |
448 | 525 | ||
449 | mu_message_get_header (msg, &hdr); | 526 | status = mu_message_get_header (msg, &hdr); |
527 | if (status) | ||
528 | mu_scm_error (FUNC_NAME, status, | ||
529 | "Cannot get message headers", SCM_BOOL_F); | ||
530 | |||
450 | for (list = LIST; list != SCM_EOL; list = SCM_CDR (list)) | 531 | for (list = LIST; list != SCM_EOL; list = SCM_CDR (list)) |
451 | { | 532 | { |
452 | SCM cell = SCM_CAR (list); | 533 | SCM cell = SCM_CAR (list); |
453 | SCM car, cdr; | 534 | SCM car, cdr; |
454 | 535 | ||
455 | SCM_ASSERT(SCM_NIMP(cell) && SCM_CONSP(cell), | 536 | SCM_ASSERT (SCM_NIMP (cell) && SCM_CONSP (cell), |
456 | cell, SCM_ARGn, FUNC_NAME); | 537 | cell, SCM_ARGn, FUNC_NAME); |
457 | car = SCM_CAR (cell); | 538 | car = SCM_CAR (cell); |
458 | cdr = SCM_CDR (cell); | 539 | cdr = SCM_CDR (cell); |
459 | SCM_ASSERT (scm_is_string (car), car, SCM_ARGn, FUNC_NAME); | 540 | SCM_ASSERT (scm_is_string (car), car, SCM_ARGn, FUNC_NAME); |
460 | SCM_ASSERT (scm_is_string (cdr), cdr, SCM_ARGn, FUNC_NAME); | 541 | SCM_ASSERT (scm_is_string (cdr), cdr, SCM_ARGn, FUNC_NAME); |
461 | mu_header_set_value (hdr, scm_i_string_chars (car), scm_i_string_chars (cdr), replace); | 542 | status = mu_header_set_value (hdr, |
543 | scm_i_string_chars (car), | ||
544 | scm_i_string_chars (cdr), replace); | ||
545 | if (status) | ||
546 | mu_scm_error (FUNC_NAME, status, | ||
547 | "Cannot set header value: message ~A, header ~A, value ~A", | ||
548 | scm_list_3 (MESG, car, cdr)); | ||
549 | |||
462 | } | 550 | } |
463 | return SCM_UNSPECIFIED; | 551 | return SCM_UNSPECIFIED; |
464 | } | 552 | } |
... | @@ -473,6 +561,7 @@ SCM_DEFINE (scm_mu_message_delete, "mu-message-delete", 1, 1, 0, | ... | @@ -473,6 +561,7 @@ SCM_DEFINE (scm_mu_message_delete, "mu-message-delete", 1, 1, 0, |
473 | mu_message_t msg; | 561 | mu_message_t msg; |
474 | mu_attribute_t attr; | 562 | mu_attribute_t attr; |
475 | int delete = 1; | 563 | int delete = 1; |
564 | int status; | ||
476 | 565 | ||
477 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 566 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
478 | msg = mu_scm_message_get (MESG); | 567 | msg = mu_scm_message_get (MESG); |
... | @@ -482,11 +571,20 @@ SCM_DEFINE (scm_mu_message_delete, "mu-message-delete", 1, 1, 0, | ... | @@ -482,11 +571,20 @@ SCM_DEFINE (scm_mu_message_delete, "mu-message-delete", 1, 1, 0, |
482 | FLAG, SCM_ARG2, FUNC_NAME); | 571 | FLAG, SCM_ARG2, FUNC_NAME); |
483 | delete = FLAG == SCM_BOOL_T; | 572 | delete = FLAG == SCM_BOOL_T; |
484 | } | 573 | } |
485 | mu_message_get_attribute (msg, &attr); | 574 | status = mu_message_get_attribute (msg, &attr); |
575 | if (status) | ||
576 | mu_scm_error (FUNC_NAME, status, | ||
577 | "Cannot get message attribute", SCM_BOOL_F); | ||
578 | |||
486 | if (delete) | 579 | if (delete) |
487 | mu_attribute_set_deleted (attr); | 580 | status = mu_attribute_set_deleted (attr); |
488 | else | 581 | else |
489 | mu_attribute_unset_deleted (attr); | 582 | status = mu_attribute_unset_deleted (attr); |
583 | |||
584 | if (status) | ||
585 | mu_scm_error (FUNC_NAME, status, | ||
586 | "Error setting message attribute", SCM_BOOL_F); | ||
587 | |||
490 | return SCM_UNSPECIFIED; | 588 | return SCM_UNSPECIFIED; |
491 | } | 589 | } |
492 | #undef FUNC_NAME | 590 | #undef FUNC_NAME |
... | @@ -499,38 +597,51 @@ SCM_DEFINE (scm_mu_message_get_flag, "mu-message-get-flag", 2, 0, 0, | ... | @@ -499,38 +597,51 @@ SCM_DEFINE (scm_mu_message_get_flag, "mu-message-get-flag", 2, 0, 0, |
499 | mu_message_t msg; | 597 | mu_message_t msg; |
500 | mu_attribute_t attr; | 598 | mu_attribute_t attr; |
501 | int ret = 0; | 599 | int ret = 0; |
600 | int status; | ||
502 | 601 | ||
503 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 602 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
504 | msg = mu_scm_message_get (MESG); | 603 | msg = mu_scm_message_get (MESG); |
505 | SCM_ASSERT (scm_is_integer (FLAG), FLAG, SCM_ARG2, FUNC_NAME); | 604 | SCM_ASSERT (scm_is_integer (FLAG), FLAG, SCM_ARG2, FUNC_NAME); |
506 | 605 | ||
507 | mu_message_get_attribute (msg, &attr); | 606 | status = mu_message_get_attribute (msg, &attr); |
607 | if (status) | ||
608 | mu_scm_error (FUNC_NAME, status, | ||
609 | "Cannot get message attribute", SCM_BOOL_F); | ||
610 | |||
508 | switch (scm_to_int32 (FLAG)) | 611 | switch (scm_to_int32 (FLAG)) |
509 | { | 612 | { |
510 | case MU_ATTRIBUTE_ANSWERED: | 613 | case MU_ATTRIBUTE_ANSWERED: |
511 | ret = mu_attribute_is_answered (attr); | 614 | ret = mu_attribute_is_answered (attr); |
512 | break; | 615 | break; |
616 | |||
513 | case MU_ATTRIBUTE_FLAGGED: | 617 | case MU_ATTRIBUTE_FLAGGED: |
514 | ret = mu_attribute_is_flagged (attr); | 618 | ret = mu_attribute_is_flagged (attr); |
515 | break; | 619 | break; |
620 | |||
516 | case MU_ATTRIBUTE_DELETED: | 621 | case MU_ATTRIBUTE_DELETED: |
517 | ret = mu_attribute_is_deleted (attr); | 622 | ret = mu_attribute_is_deleted (attr); |
518 | break; | 623 | break; |
624 | |||
519 | case MU_ATTRIBUTE_DRAFT: | 625 | case MU_ATTRIBUTE_DRAFT: |
520 | ret = mu_attribute_is_draft (attr); | 626 | ret = mu_attribute_is_draft (attr); |
521 | break; | 627 | break; |
628 | |||
522 | case MU_ATTRIBUTE_SEEN: | 629 | case MU_ATTRIBUTE_SEEN: |
523 | ret = mu_attribute_is_seen (attr); | 630 | ret = mu_attribute_is_seen (attr); |
524 | break; | 631 | break; |
632 | |||
525 | case MU_ATTRIBUTE_READ: | 633 | case MU_ATTRIBUTE_READ: |
526 | ret = mu_attribute_is_read (attr); | 634 | ret = mu_attribute_is_read (attr); |
527 | break; | 635 | break; |
636 | |||
528 | case MU_ATTRIBUTE_MODIFIED: | 637 | case MU_ATTRIBUTE_MODIFIED: |
529 | ret = mu_attribute_is_modified (attr); | 638 | ret = mu_attribute_is_modified (attr); |
530 | break; | 639 | break; |
640 | |||
531 | case MU_ATTRIBUTE_RECENT: | 641 | case MU_ATTRIBUTE_RECENT: |
532 | ret = mu_attribute_is_recent (attr); | 642 | ret = mu_attribute_is_recent (attr); |
533 | break; | 643 | break; |
644 | |||
534 | default: | 645 | default: |
535 | mu_attribute_get_flags (attr, &ret); | 646 | mu_attribute_get_flags (attr, &ret); |
536 | ret &= scm_to_int32 (FLAG); | 647 | ret &= scm_to_int32 (FLAG); |
... | @@ -548,6 +659,7 @@ SCM_DEFINE (scm_mu_message_set_flag, "mu-message-set-flag", 2, 1, 0, | ... | @@ -548,6 +659,7 @@ SCM_DEFINE (scm_mu_message_set_flag, "mu-message-set-flag", 2, 1, 0, |
548 | mu_message_t msg; | 659 | mu_message_t msg; |
549 | mu_attribute_t attr; | 660 | mu_attribute_t attr; |
550 | int value = 1; | 661 | int value = 1; |
662 | int status; | ||
551 | 663 | ||
552 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 664 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
553 | msg = mu_scm_message_get (MESG); | 665 | msg = mu_scm_message_get (MESG); |
... | @@ -560,61 +672,79 @@ SCM_DEFINE (scm_mu_message_set_flag, "mu-message-set-flag", 2, 1, 0, | ... | @@ -560,61 +672,79 @@ SCM_DEFINE (scm_mu_message_set_flag, "mu-message-set-flag", 2, 1, 0, |
560 | value = VALUE == SCM_BOOL_T; | 672 | value = VALUE == SCM_BOOL_T; |
561 | } | 673 | } |
562 | 674 | ||
563 | mu_message_get_attribute (msg, &attr); | 675 | status = mu_message_get_attribute (msg, &attr); |
676 | if (status) | ||
677 | mu_scm_error (FUNC_NAME, status, | ||
678 | "Cannot get message attribute", SCM_BOOL_F); | ||
679 | |||
680 | status = 0; | ||
564 | switch (scm_to_int32 (FLAG)) | 681 | switch (scm_to_int32 (FLAG)) |
565 | { | 682 | { |
566 | case MU_ATTRIBUTE_ANSWERED: | 683 | case MU_ATTRIBUTE_ANSWERED: |
567 | if (value) | 684 | if (value) |
568 | mu_attribute_set_answered (attr); | 685 | status = mu_attribute_set_answered (attr); |
569 | else | 686 | else |
570 | mu_attribute_unset_answered (attr); | 687 | status = mu_attribute_unset_answered (attr); |
571 | break; | 688 | break; |
689 | |||
572 | case MU_ATTRIBUTE_FLAGGED: | 690 | case MU_ATTRIBUTE_FLAGGED: |
573 | if (value) | 691 | if (value) |
574 | mu_attribute_set_flagged (attr); | 692 | status = mu_attribute_set_flagged (attr); |
575 | else | 693 | else |
576 | mu_attribute_unset_flagged (attr); | 694 | status = mu_attribute_unset_flagged (attr); |
577 | break; | 695 | break; |
696 | |||
578 | case MU_ATTRIBUTE_DELETED: | 697 | case MU_ATTRIBUTE_DELETED: |
579 | if (value) | 698 | if (value) |
580 | mu_attribute_set_deleted (attr); | 699 | status = mu_attribute_set_deleted (attr); |
581 | else | 700 | else |
582 | mu_attribute_unset_deleted (attr); | 701 | status = mu_attribute_unset_deleted (attr); |
583 | break; | 702 | break; |
703 | |||
584 | case MU_ATTRIBUTE_DRAFT: | 704 | case MU_ATTRIBUTE_DRAFT: |
585 | if (value) | 705 | if (value) |
586 | mu_attribute_set_draft (attr); | 706 | status = mu_attribute_set_draft (attr); |
587 | else | 707 | else |
588 | mu_attribute_unset_draft (attr); | 708 | status = mu_attribute_unset_draft (attr); |
589 | break; | 709 | break; |
710 | |||
590 | case MU_ATTRIBUTE_SEEN: | 711 | case MU_ATTRIBUTE_SEEN: |
591 | if (value) | 712 | if (value) |
592 | mu_attribute_set_seen (attr); | 713 | status = mu_attribute_set_seen (attr); |
593 | else | 714 | else |
594 | mu_attribute_unset_seen (attr); | 715 | status = mu_attribute_unset_seen (attr); |
595 | break; | 716 | break; |
717 | |||
596 | case MU_ATTRIBUTE_READ: | 718 | case MU_ATTRIBUTE_READ: |
597 | if (value) | 719 | if (value) |
598 | mu_attribute_set_read (attr); | 720 | status = mu_attribute_set_read (attr); |
599 | else | 721 | else |
600 | mu_attribute_unset_read (attr); | 722 | status = mu_attribute_unset_read (attr); |
601 | break; | 723 | break; |
724 | |||
602 | case MU_ATTRIBUTE_MODIFIED: | 725 | case MU_ATTRIBUTE_MODIFIED: |
603 | if (value) | 726 | if (value) |
604 | mu_attribute_set_modified (attr); | 727 | status = mu_attribute_set_modified (attr); |
605 | else | 728 | else |
606 | mu_attribute_clear_modified (attr); | 729 | status = mu_attribute_clear_modified (attr); |
607 | break; | 730 | break; |
731 | |||
608 | case MU_ATTRIBUTE_RECENT: | 732 | case MU_ATTRIBUTE_RECENT: |
609 | if (value) | 733 | if (value) |
610 | mu_attribute_set_recent (attr); | 734 | status = mu_attribute_set_recent (attr); |
611 | else | 735 | else |
612 | mu_attribute_unset_recent (attr); | 736 | status = mu_attribute_unset_recent (attr); |
613 | break; | 737 | break; |
738 | |||
614 | default: | 739 | default: |
615 | if (value) | 740 | if (value) |
616 | mu_attribute_set_flags (attr, scm_to_int32 (FLAG)); | 741 | status = mu_attribute_set_flags (attr, scm_to_int32 (FLAG)); |
617 | } | 742 | } |
743 | |||
744 | if (status) | ||
745 | mu_scm_error (FUNC_NAME, status, | ||
746 | "Error setting message attribute", SCM_BOOL_F); | ||
747 | |||
618 | return SCM_UNSPECIFIED; | 748 | return SCM_UNSPECIFIED; |
619 | } | 749 | } |
620 | #undef FUNC_NAME | 750 | #undef FUNC_NAME |
... | @@ -626,11 +756,15 @@ SCM_DEFINE (scm_mu_message_get_user_flag, "mu-message-get-user-flag", 2, 0, 0, | ... | @@ -626,11 +756,15 @@ SCM_DEFINE (scm_mu_message_get_user_flag, "mu-message-get-user-flag", 2, 0, 0, |
626 | { | 756 | { |
627 | mu_message_t msg; | 757 | mu_message_t msg; |
628 | mu_attribute_t attr; | 758 | mu_attribute_t attr; |
759 | int status; | ||
629 | 760 | ||
630 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 761 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
631 | msg = mu_scm_message_get (MESG); | 762 | msg = mu_scm_message_get (MESG); |
632 | SCM_ASSERT (scm_is_integer (FLAG), FLAG, SCM_ARG2, FUNC_NAME); | 763 | SCM_ASSERT (scm_is_integer (FLAG), FLAG, SCM_ARG2, FUNC_NAME); |
633 | mu_message_get_attribute (msg, &attr); | 764 | status = mu_message_get_attribute (msg, &attr); |
765 | if (status) | ||
766 | mu_scm_error (FUNC_NAME, status, | ||
767 | "Cannot get message attribute", SCM_BOOL_F); | ||
634 | return mu_attribute_is_userflag (attr, scm_to_int32 (FLAG)) ? | 768 | return mu_attribute_is_userflag (attr, scm_to_int32 (FLAG)) ? |
635 | SCM_BOOL_T : SCM_BOOL_F; | 769 | SCM_BOOL_T : SCM_BOOL_F; |
636 | } | 770 | } |
... | @@ -646,6 +780,7 @@ SCM_DEFINE (scm_mu_message_set_user_flag, "mu-message-set-user-flag", 2, 1, 0, | ... | @@ -646,6 +780,7 @@ SCM_DEFINE (scm_mu_message_set_user_flag, "mu-message-set-user-flag", 2, 1, 0, |
646 | mu_message_t msg; | 780 | mu_message_t msg; |
647 | mu_attribute_t attr; | 781 | mu_attribute_t attr; |
648 | int set = 1; | 782 | int set = 1; |
783 | int status; | ||
649 | 784 | ||
650 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 785 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
651 | msg = mu_scm_message_get (MESG); | 786 | msg = mu_scm_message_get (MESG); |
... | @@ -658,7 +793,11 @@ SCM_DEFINE (scm_mu_message_set_user_flag, "mu-message-set-user-flag", 2, 1, 0, | ... | @@ -658,7 +793,11 @@ SCM_DEFINE (scm_mu_message_set_user_flag, "mu-message-set-user-flag", 2, 1, 0, |
658 | set = VALUE == SCM_BOOL_T; | 793 | set = VALUE == SCM_BOOL_T; |
659 | } | 794 | } |
660 | 795 | ||
661 | mu_message_get_attribute (msg, &attr); | 796 | status = mu_message_get_attribute (msg, &attr); |
797 | if (status) | ||
798 | mu_scm_error (FUNC_NAME, status, | ||
799 | "Cannot get message attribute", SCM_BOOL_F); | ||
800 | |||
662 | if (set) | 801 | if (set) |
663 | mu_attribute_set_userflag (attr, scm_to_int32 (FLAG)); | 802 | mu_attribute_set_userflag (attr, scm_to_int32 (FLAG)); |
664 | else | 803 | else |
... | @@ -680,6 +819,7 @@ SCM_DEFINE (scm_mu_message_get_port, "mu-message-get-port", 2, 1, 0, | ... | @@ -680,6 +819,7 @@ SCM_DEFINE (scm_mu_message_get_port, "mu-message-get-port", 2, 1, 0, |
680 | { | 819 | { |
681 | mu_message_t msg; | 820 | mu_message_t msg; |
682 | mu_stream_t stream = NULL; | 821 | mu_stream_t stream = NULL; |
822 | int status; | ||
683 | 823 | ||
684 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 824 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
685 | SCM_ASSERT (scm_is_string (MODE), MODE, SCM_ARG2, FUNC_NAME); | 825 | SCM_ASSERT (scm_is_string (MODE), MODE, SCM_ARG2, FUNC_NAME); |
... | @@ -690,17 +830,27 @@ SCM_DEFINE (scm_mu_message_get_port, "mu-message-get-port", 2, 1, 0, | ... | @@ -690,17 +830,27 @@ SCM_DEFINE (scm_mu_message_get_port, "mu-message-get-port", 2, 1, 0, |
690 | { | 830 | { |
691 | SCM_ASSERT (SCM_IMP (FULL) && SCM_BOOLP (FULL), | 831 | SCM_ASSERT (SCM_IMP (FULL) && SCM_BOOLP (FULL), |
692 | FULL, SCM_ARG3, FUNC_NAME); | 832 | FULL, SCM_ARG3, FUNC_NAME); |
693 | if (FULL == SCM_BOOL_T && mu_message_get_stream (msg, &stream)) | 833 | if (FULL == SCM_BOOL_T) |
694 | return SCM_BOOL_F; | 834 | { |
835 | status = mu_message_get_stream (msg, &stream); | ||
836 | if (status) | ||
837 | mu_scm_error (FUNC_NAME, status, "Cannot get message stream", | ||
838 | SCM_BOOL_F); | ||
839 | } | ||
695 | } | 840 | } |
696 | 841 | ||
697 | if (!stream) | 842 | if (!stream) |
698 | { | 843 | { |
699 | mu_body_t body = NULL; | 844 | mu_body_t body = NULL; |
700 | 845 | ||
701 | if (mu_message_get_body (msg, &body) | 846 | status = mu_message_get_body (msg, &body); |
702 | || mu_body_get_stream (body, &stream)) | 847 | if (status) |
703 | return SCM_BOOL_F; | 848 | mu_scm_error (FUNC_NAME, status, "Cannot get message body", |
849 | SCM_BOOL_F); | ||
850 | status = mu_body_get_stream (body, &stream); | ||
851 | if (status) | ||
852 | mu_scm_error (FUNC_NAME, status, "Cannot get message body stream", | ||
853 | SCM_BOOL_F); | ||
704 | } | 854 | } |
705 | 855 | ||
706 | return mu_port_make_from_stream (MESG, stream, | 856 | return mu_port_make_from_stream (MESG, stream, |
... | @@ -716,11 +866,13 @@ SCM_DEFINE (scm_mu_message_get_body, "mu-message-get-body", 1, 0, 0, | ... | @@ -716,11 +866,13 @@ SCM_DEFINE (scm_mu_message_get_body, "mu-message-get-body", 1, 0, 0, |
716 | { | 866 | { |
717 | mu_message_t msg; | 867 | mu_message_t msg; |
718 | mu_body_t body = NULL; | 868 | mu_body_t body = NULL; |
869 | int status; | ||
719 | 870 | ||
720 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 871 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
721 | msg = mu_scm_message_get (MESG); | 872 | msg = mu_scm_message_get (MESG); |
722 | if (mu_message_get_body (msg, &body)) | 873 | status = mu_message_get_body (msg, &body); |
723 | return SCM_BOOL_F; | 874 | if (status) |
875 | mu_scm_error (FUNC_NAME, status, "Cannot get message body", SCM_BOOL_F); | ||
724 | return mu_scm_body_create (MESG, body); | 876 | return mu_scm_body_create (MESG, body); |
725 | } | 877 | } |
726 | #undef FUNC_NAME | 878 | #undef FUNC_NAME |
... | @@ -749,6 +901,7 @@ SCM_DEFINE (scm_mu_message_get_num_parts, "mu-message-get-num-parts", 1, 0, 0, | ... | @@ -749,6 +901,7 @@ SCM_DEFINE (scm_mu_message_get_num_parts, "mu-message-get-num-parts", 1, 0, 0, |
749 | mu_message_t msg; | 901 | mu_message_t msg; |
750 | int ismime = 0; | 902 | int ismime = 0; |
751 | size_t nparts = 0; | 903 | size_t nparts = 0; |
904 | int status; | ||
752 | 905 | ||
753 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 906 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
754 | msg = mu_scm_message_get (MESG); | 907 | msg = mu_scm_message_get (MESG); |
... | @@ -756,7 +909,11 @@ SCM_DEFINE (scm_mu_message_get_num_parts, "mu-message-get-num-parts", 1, 0, 0, | ... | @@ -756,7 +909,11 @@ SCM_DEFINE (scm_mu_message_get_num_parts, "mu-message-get-num-parts", 1, 0, 0, |
756 | if (!ismime) | 909 | if (!ismime) |
757 | return SCM_BOOL_F; | 910 | return SCM_BOOL_F; |
758 | 911 | ||
759 | mu_message_get_num_parts (msg, &nparts); | 912 | status = mu_message_get_num_parts (msg, &nparts); |
913 | if (status) | ||
914 | mu_scm_error (FUNC_NAME, status, | ||
915 | "Cannot get number of parts in the message ~A", | ||
916 | scm_list_1 (MESG)); | ||
760 | return mu_scm_makenum (nparts); | 917 | return mu_scm_makenum (nparts); |
761 | } | 918 | } |
762 | #undef FUNC_NAME | 919 | #undef FUNC_NAME |
... | @@ -768,6 +925,7 @@ SCM_DEFINE (scm_mu_message_get_part, "mu-message-get-part", 2, 0, 0, | ... | @@ -768,6 +925,7 @@ SCM_DEFINE (scm_mu_message_get_part, "mu-message-get-part", 2, 0, 0, |
768 | { | 925 | { |
769 | mu_message_t msg, submsg; | 926 | mu_message_t msg, submsg; |
770 | int ismime = 0; | 927 | int ismime = 0; |
928 | int status; | ||
771 | 929 | ||
772 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | 930 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); |
773 | SCM_ASSERT (scm_is_integer (PART), PART, SCM_ARG2, FUNC_NAME); | 931 | SCM_ASSERT (scm_is_integer (PART), PART, SCM_ARG2, FUNC_NAME); |
... | @@ -777,8 +935,12 @@ SCM_DEFINE (scm_mu_message_get_part, "mu-message-get-part", 2, 0, 0, | ... | @@ -777,8 +935,12 @@ SCM_DEFINE (scm_mu_message_get_part, "mu-message-get-part", 2, 0, 0, |
777 | if (!ismime) | 935 | if (!ismime) |
778 | return SCM_BOOL_F; | 936 | return SCM_BOOL_F; |
779 | 937 | ||
780 | if (mu_message_get_part (msg, scm_to_int32 (PART), &submsg)) | 938 | status = mu_message_get_part (msg, scm_to_int32 (PART), &submsg); |
781 | return SCM_BOOL_F; | 939 | if (status) |
940 | mu_scm_error (FUNC_NAME, status, | ||
941 | "Cannot get number of part ~A from the message ~A", | ||
942 | scm_list_2 (PART, MESG)); | ||
943 | |||
782 | return mu_scm_message_create (MESG, submsg); | 944 | return mu_scm_message_create (MESG, submsg); |
783 | } | 945 | } |
784 | #undef FUNC_NAME | 946 | #undef FUNC_NAME |
... | @@ -825,12 +987,11 @@ SCM_DEFINE (scm_mu_message_send, "mu-message-send", 1, 3, 0, | ... | @@ -825,12 +987,11 @@ SCM_DEFINE (scm_mu_message_send, "mu-message-send", 1, 3, 0, |
825 | TO, SCM_ARG4, FUNC_NAME); | 987 | TO, SCM_ARG4, FUNC_NAME); |
826 | } | 988 | } |
827 | 989 | ||
828 | if (mu_mailer_create (&mailer, mailer_name)) | 990 | status = mu_mailer_create (&mailer, mailer_name); |
829 | { | 991 | if (status) |
830 | return SCM_BOOL_F; | 992 | mu_scm_error (FUNC_NAME, status, "Cannot get create mailer", SCM_BOOL_F); |
831 | } | ||
832 | 993 | ||
833 | if (scm_to_int32 (MU_SCM_SYMBOL_VALUE("mu-debug"))) | 994 | if (scm_to_int32 (MU_SCM_SYMBOL_VALUE ("mu-debug"))) |
834 | { | 995 | { |
835 | mu_debug_t debug = NULL; | 996 | mu_debug_t debug = NULL; |
836 | mu_mailer_get_debug (mailer, &debug); | 997 | mu_mailer_get_debug (mailer, &debug); |
... | @@ -841,14 +1002,37 @@ SCM_DEFINE (scm_mu_message_send, "mu-message-send", 1, 3, 0, | ... | @@ -841,14 +1002,37 @@ SCM_DEFINE (scm_mu_message_send, "mu-message-send", 1, 3, 0, |
841 | if (status == 0) | 1002 | if (status == 0) |
842 | { | 1003 | { |
843 | status = mu_mailer_send_message (mailer, msg, from, to); | 1004 | status = mu_mailer_send_message (mailer, msg, from, to); |
1005 | if (status) | ||
1006 | mu_scm_error (FUNC_NAME, status, "Cannot send message", SCM_BOOL_F); | ||
1007 | |||
844 | mu_mailer_close (mailer); | 1008 | mu_mailer_close (mailer); |
845 | } | 1009 | } |
1010 | else | ||
1011 | mu_scm_error (FUNC_NAME, status, "Cannot open mailer", SCM_BOOL_F); | ||
846 | mu_mailer_destroy (&mailer); | 1012 | mu_mailer_destroy (&mailer); |
847 | 1013 | ||
848 | return status == 0 ? SCM_BOOL_T : SCM_BOOL_F; | 1014 | return status == 0 ? SCM_BOOL_T : SCM_BOOL_F; |
849 | } | 1015 | } |
850 | #undef FUNC_NAME | 1016 | #undef FUNC_NAME |
851 | 1017 | ||
1018 | SCM_DEFINE (scm_mu_message_get_uid, "mu-message-get-uid", 1, 0, 0, | ||
1019 | (SCM MESG), | ||
1020 | "Returns uid of the message MESG\n") | ||
1021 | #define FUNC_NAME s_scm_mu_message_get_uid | ||
1022 | { | ||
1023 | mu_message_t msg; | ||
1024 | int status; | ||
1025 | size_t uid; | ||
1026 | |||
1027 | SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME); | ||
1028 | msg = mu_scm_message_get (MESG); | ||
1029 | status = mu_message_get_uid (msg, &uid); | ||
1030 | if (status) | ||
1031 | mu_scm_error (FUNC_NAME, status, "Cannot get message uid", SCM_BOOL_F); | ||
1032 | return scm_from_size_t (uid); | ||
1033 | } | ||
1034 | #undef FUNC_NAME | ||
1035 | |||
852 | /* Initialize the module */ | 1036 | /* Initialize the module */ |
853 | 1037 | ||
854 | void | 1038 | void | ... | ... |
-
Please register or sign in to post a comment