Commit 0ee5432e 0ee5432e070b5ab12f6cf723dc9ae72942328f29 by Sergey Poznyakoff

Added new primitives:

	mu_message_copy
	mu_message_delete
	mu_message_get_flag
	mu_message_set_flag
	mu_message_get_user_flag
	mu_message_set_user_flag
1 parent 83a142e1
...@@ -149,6 +149,52 @@ SCM_DEFINE (mu_message_create, "mu-message-create", 0, 0, 0, ...@@ -149,6 +149,52 @@ SCM_DEFINE (mu_message_create, "mu-message-create", 0, 0, 0,
149 } 149 }
150 #undef FUNC_NAME 150 #undef FUNC_NAME
151 151
152 /* FIXME: This changes envelope date */
153 SCM_DEFINE (mu_message_copy, "mu-message-copy", 1, 0, 0,
154 (SCM MESG),
155 "Creates the copy of the given message.\n")
156 #define FUNC_NAME s_mu_message_copy
157 {
158 message_t msg, newmsg;
159 stream_t in = NULL, out = NULL;
160 char buffer[512];
161 size_t off, n;
162
163 SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME);
164 msg = mu_scm_message_get (MESG);
165
166 if (message_get_stream (msg, &in))
167 return SCM_BOOL_F;
168
169 if (message_create (&newmsg, NULL))
170 return SCM_BOOL_F;
171
172 if (message_get_stream (newmsg, &out))
173 {
174 message_destroy (&newmsg, NULL);
175 return SCM_BOOL_F;
176 }
177
178 off = 0;
179 while (stream_read (in, buffer, sizeof (buffer) - 1, off, &n) == 0
180 && n != 0)
181 {
182 int wr;
183
184 stream_write (out, buffer, n, off, &wr);
185 off += n;
186 if (wr != n)
187 {
188 message_destroy (&newmsg, NULL);
189 return SCM_BOOL_F;
190 }
191 }
192
193 return mu_scm_message_create (SCM_BOOL_F, newmsg);
194 }
195 #undef FUNC_NAME
196
197
152 SCM_DEFINE (mu_message_set_header, "mu-message-set-header", 3, 1, 0, 198 SCM_DEFINE (mu_message_set_header, "mu-message-set-header", 3, 1, 0,
153 (SCM MESG, SCM HEADER, SCM VALUE, SCM REPLACE), 199 (SCM MESG, SCM HEADER, SCM VALUE, SCM REPLACE),
154 "Sets new VALUE to the header HEADER of the message MESG.\n" 200 "Sets new VALUE to the header HEADER of the message MESG.\n"
...@@ -184,7 +230,7 @@ SCM_DEFINE (mu_message_set_header, "mu-message-set-header", 3, 1, 0, ...@@ -184,7 +230,7 @@ SCM_DEFINE (mu_message_set_header, "mu-message-set-header", 3, 1, 0,
184 230
185 SCM_DEFINE (mu_message_get_sender, "mu-message-get-sender", 1, 0, 0, 231 SCM_DEFINE (mu_message_get_sender, "mu-message-get-sender", 1, 0, 0,
186 (SCM MESG), 232 (SCM MESG),
187 "Returns the sender email address for the message MESG") 233 "Returns the sender email address for the message MESG.")
188 #define FUNC_NAME s_mu_message_get_sender 234 #define FUNC_NAME s_mu_message_get_sender
189 { 235 {
190 message_t msg; 236 message_t msg;
...@@ -320,9 +366,215 @@ SCM_DEFINE (mu_message_set_header_fields, "mu-message-set-header-fields", 2, 1, ...@@ -320,9 +366,215 @@ SCM_DEFINE (mu_message_set_header_fields, "mu-message-set-header-fields", 2, 1,
320 } 366 }
321 #undef FUNC_NAME 367 #undef FUNC_NAME
322 368
369 SCM_DEFINE (mu_message_delete, "mu-message-delete", 1, 1, 0,
370 (SCM MESG, SCM FLAG),
371 "Mark given message as deleted. Optional FLAG allows to toggle deleted mark\n"
372 "The message is deleted if it is #t and undeleted if it is #f")
373 #define FUNC_NAME s_mu_message_delete
374 {
375 message_t msg;
376 attribute_t attr;
377 int delete = 1;
378
379 SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME);
380 msg = mu_scm_message_get (MESG);
381 if (!SCM_UNBNDP (FLAG))
382 {
383 SCM_ASSERT (SCM_IMP (FLAG) && SCM_BOOLP (FLAG),
384 FLAG, SCM_ARG2, FUNC_NAME);
385 delete = FLAG == SCM_BOOL_T;
386 }
387 message_get_attribute (msg, &attr);
388 if (delete)
389 attribute_set_deleted (attr);
390 else
391 attribute_unset_deleted (attr);
392 return SCM_UNDEFINED;
393 }
394 #undef FUNC_NAME
395
396 SCM_DEFINE (mu_message_get_flag, "mu-message-get-flag", 2, 0, 0,
397 (SCM MESG, SCM FLAG),
398 "Return value of the attribute FLAG.")
399 #define FUNC_NAME s_mu_message_get_flag
400 {
401 message_t msg;
402 attribute_t attr;
403 int ret = 0;
404
405 SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME);
406 msg = mu_scm_message_get (MESG);
407 SCM_ASSERT (SCM_IMP (FLAG) && SCM_INUMP (FLAG), FLAG, SCM_ARG2, FUNC_NAME);
408
409 message_get_attribute (msg, &attr);
410 switch (SCM_INUM (FLAG))
411 {
412 case MU_ATTRIBUTE_ANSWERED:
413 ret = attribute_is_answered (attr);
414 break;
415 case MU_ATTRIBUTE_FLAGGED:
416 ret = attribute_is_flagged (attr);
417 break;
418 case MU_ATTRIBUTE_DELETED:
419 ret = attribute_is_deleted (attr);
420 break;
421 case MU_ATTRIBUTE_DRAFT:
422 ret = attribute_is_draft (attr);
423 break;
424 case MU_ATTRIBUTE_SEEN:
425 ret = attribute_is_seen (attr);
426 break;
427 case MU_ATTRIBUTE_READ:
428 ret = attribute_is_read (attr);
429 break;
430 case MU_ATTRIBUTE_MODIFIED:
431 ret = attribute_is_modified (attr);
432 break;
433 case MU_ATTRIBUTE_RECENT:
434 ret = attribute_is_recent (attr);
435 break;
436 default:
437 attribute_get_flags (attr, &ret);
438 ret &= SCM_INUM (FLAG);
439 }
440 return ret ? SCM_BOOL_T : SCM_BOOL_F;
441 }
442 #undef FUNC_NAME
443
444 SCM_DEFINE (mu_message_set_flag, "mu-message-set-flag", 2, 1, 0,
445 (SCM MESG, SCM FLAG, SCM VALUE),
446 "Set the given attribute of the message. If optional VALUE is #f, the\n"
447 "attribute is unset.")
448 #define FUNC_NAME s_mu_message_set_flag
449 {
450 message_t msg;
451 attribute_t attr;
452 int value = 1;
453
454 SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME);
455 msg = mu_scm_message_get (MESG);
456 SCM_ASSERT (SCM_IMP (FLAG) && SCM_INUMP (FLAG), FLAG, SCM_ARG2, FUNC_NAME);
457
458 if (!SCM_UNBNDP (VALUE))
459 {
460 SCM_ASSERT (SCM_IMP (VALUE) && SCM_BOOLP (VALUE),
461 VALUE, SCM_ARG3, FUNC_NAME);
462 value = VALUE == SCM_BOOL_T;
463 }
464
465 message_get_attribute (msg, &attr);
466 switch (SCM_INUM (FLAG))
467 {
468 case MU_ATTRIBUTE_ANSWERED:
469 if (value)
470 attribute_set_answered (attr);
471 else
472 attribute_unset_answered (attr);
473 break;
474 case MU_ATTRIBUTE_FLAGGED:
475 if (value)
476 attribute_set_flagged (attr);
477 else
478 attribute_unset_flagged (attr);
479 break;
480 case MU_ATTRIBUTE_DELETED:
481 if (value)
482 attribute_set_deleted (attr);
483 else
484 attribute_unset_deleted (attr);
485 break;
486 case MU_ATTRIBUTE_DRAFT:
487 if (value)
488 attribute_set_draft (attr);
489 else
490 attribute_unset_draft (attr);
491 break;
492 case MU_ATTRIBUTE_SEEN:
493 if (value)
494 attribute_set_seen (attr);
495 else
496 attribute_unset_seen (attr);
497 break;
498 case MU_ATTRIBUTE_READ:
499 if (value)
500 attribute_set_read (attr);
501 else
502 attribute_unset_read (attr);
503 break;
504 case MU_ATTRIBUTE_MODIFIED:
505 if (value)
506 attribute_set_modified (attr);
507 else
508 attribute_clear_modified (attr);
509 break;
510 case MU_ATTRIBUTE_RECENT:
511 if (value)
512 attribute_set_recent (attr);
513 else
514 attribute_unset_recent (attr);
515 break;
516 default:
517 if (value)
518 attribute_set_flags (attr, SCM_INUM (FLAG));
519 }
520 return SCM_UNDEFINED;
521 }
522 #undef FUNC_NAME
523
524 SCM_DEFINE (mu_message_get_user_flag, "mu-message-get-user-flag", 2, 0, 0,
525 (SCM MESG, SCM FLAG),
526 "Returns value of the user attribute FLAG.")
527 #define FUNC_NAME s_mu_message_get_user_flag
528 {
529 message_t msg;
530 attribute_t attr;
531 int ret = 0;
532
533 SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME);
534 msg = mu_scm_message_get (MESG);
535 SCM_ASSERT (SCM_IMP (FLAG) && SCM_INUMP (FLAG), FLAG, SCM_ARG2, FUNC_NAME);
536 message_get_attribute (msg, &attr);
537 return attribute_is_userflag (attr, SCM_INUM (FLAG)) ?
538 SCM_BOOL_T : SCM_BOOL_F;
539 }
540 #undef FUNC_NAME
541
542
543 SCM_DEFINE (mu_message_set_user_flag, "mu-message-set-user-flag", 2, 1, 0,
544 (SCM MESG, SCM FLAG, SCM VALUE),
545 "Set the given user attribute of the message. If optional VALUE is\n"
546 "#f, the attribute is unset.")
547 #define FUNC_NAME s_mu_message_set_user_flag
548 {
549 message_t msg;
550 attribute_t attr;
551 int set = 1;
552
553 SCM_ASSERT (mu_scm_is_message (MESG), MESG, SCM_ARG1, FUNC_NAME);
554 msg = mu_scm_message_get (MESG);
555 SCM_ASSERT (SCM_IMP (FLAG) && SCM_INUMP (FLAG), FLAG, SCM_ARG2, FUNC_NAME);
556
557 if (!SCM_UNBNDP (VALUE))
558 {
559 SCM_ASSERT (SCM_IMP (VALUE) && SCM_BOOLP (VALUE),
560 VALUE, SCM_ARG3, FUNC_NAME);
561 set = VALUE == SCM_BOOL_T;
562 }
563
564 message_get_attribute (msg, &attr);
565 if (set)
566 attribute_set_userflag (attr, SCM_INUM (FLAG));
567 else
568 attribute_unset_userflag (attr, SCM_INUM (FLAG));
569 return SCM_UNDEFINED;
570 }
571 #undef FUNC_NAME
572
573
574
323 SCM_DEFINE (mu_message_get_body, "mu-message-get-body", 1, 0, 0, 575 SCM_DEFINE (mu_message_get_body, "mu-message-get-body", 1, 0, 0,
324 (SCM MESG), 576 (SCM MESG),
325 "Returns the message body for the message MESG") 577 "Returns the message body for the message MESG.")
326 #define FUNC_NAME s_mu_message_get_body 578 #define FUNC_NAME s_mu_message_get_body
327 { 579 {
328 message_t msg; 580 message_t msg;
......