2010-05-22 07:45:40 +02:00
|
|
|
/* The Ruby interface to the notmuch mail library
|
|
|
|
*
|
2011-10-04 15:41:52 +02:00
|
|
|
* Copyright © 2010, 2011 Ali Polatel
|
2010-05-22 07:45:40 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2016-06-02 18:26:14 +02:00
|
|
|
* along with this program. If not, see https://www.gnu.org/licenses/ .
|
2010-05-22 07:45:40 +02:00
|
|
|
*
|
|
|
|
* Author: Ali Polatel <alip@exherbo.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
2010-05-26 17:54:25 +02:00
|
|
|
/*
|
2011-09-24 14:25:24 +02:00
|
|
|
* call-seq: MESSAGE.destroy! => nil
|
2010-05-26 17:54:25 +02:00
|
|
|
*
|
|
|
|
* Destroys the message, freeing all resources allocated for it.
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_destroy (VALUE self)
|
2010-05-26 17:54:25 +02:00
|
|
|
{
|
2021-05-15 23:21:03 +02:00
|
|
|
notmuch_rb_object_destroy (self, ¬much_rb_message_type);
|
2010-05-26 17:54:25 +02:00
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2010-05-22 07:45:40 +02:00
|
|
|
/*
|
|
|
|
* call-seq: MESSAGE.message_id => String
|
|
|
|
*
|
|
|
|
* Get the message ID of 'message'.
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_get_message_id (VALUE self)
|
2010-05-22 07:45:40 +02:00
|
|
|
{
|
|
|
|
const char *msgid;
|
2010-05-26 17:54:25 +02:00
|
|
|
notmuch_message_t *message;
|
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
msgid = notmuch_message_get_message_id (message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
return rb_str_new2 (msgid);
|
2010-05-22 07:45:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq: MESSAGE.thread_id => String
|
|
|
|
*
|
|
|
|
* Get the thread ID of 'message'.
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_get_thread_id (VALUE self)
|
2010-05-22 07:45:40 +02:00
|
|
|
{
|
|
|
|
const char *tid;
|
2010-05-26 17:54:25 +02:00
|
|
|
notmuch_message_t *message;
|
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
tid = notmuch_message_get_thread_id (message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
return rb_str_new2 (tid);
|
2010-05-22 07:45:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq: MESSAGE.replies => MESSAGES
|
|
|
|
*
|
|
|
|
* Get a Notmuch::Messages enumerable for all of the replies to 'message'.
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_get_replies (VALUE self)
|
2010-05-22 07:45:40 +02:00
|
|
|
{
|
2010-05-26 17:54:25 +02:00
|
|
|
notmuch_messages_t *messages;
|
|
|
|
notmuch_message_t *message;
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
messages = notmuch_message_get_replies (message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2021-05-15 23:21:02 +02:00
|
|
|
return Data_Wrap_Notmuch_Object (notmuch_rb_cMessages, ¬much_rb_messages_type, messages);
|
2010-05-22 07:45:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq: MESSAGE.filename => String
|
|
|
|
*
|
|
|
|
* Get a filename for the email corresponding to 'message'
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_get_filename (VALUE self)
|
2010-05-22 07:45:40 +02:00
|
|
|
{
|
|
|
|
const char *fname;
|
2010-05-26 17:54:25 +02:00
|
|
|
notmuch_message_t *message;
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
fname = notmuch_message_get_filename (message);
|
2010-05-26 17:54:25 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
return rb_str_new2 (fname);
|
2010-05-22 07:45:40 +02:00
|
|
|
}
|
|
|
|
|
2011-01-10 15:03:31 +01:00
|
|
|
/*
|
2014-01-30 20:11:51 +01:00
|
|
|
* call-seq: MESSAGE.filenames => FILENAMES
|
2011-01-10 15:03:31 +01:00
|
|
|
*
|
|
|
|
* Get all filenames for the email corresponding to MESSAGE.
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_get_filenames (VALUE self)
|
2011-01-10 15:03:31 +01:00
|
|
|
{
|
|
|
|
notmuch_filenames_t *fnames;
|
|
|
|
notmuch_message_t *message;
|
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2011-01-10 15:03:31 +01:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
fnames = notmuch_message_get_filenames (message);
|
2011-01-10 15:03:31 +01:00
|
|
|
|
2023-03-27 23:59:40 +02:00
|
|
|
return notmuch_rb_filenames_get (fnames);
|
2011-01-10 15:03:31 +01:00
|
|
|
}
|
|
|
|
|
2010-05-22 07:45:40 +02:00
|
|
|
/*
|
2011-10-04 15:41:52 +02:00
|
|
|
* call-seq: MESSAGE.get_flag (flag) => true or false
|
2010-05-22 07:45:40 +02:00
|
|
|
*
|
|
|
|
* Get a value of a flag for the email corresponding to 'message'
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_get_flag (VALUE self, VALUE flagv)
|
2010-05-22 07:45:40 +02:00
|
|
|
{
|
2010-05-26 17:54:25 +02:00
|
|
|
notmuch_message_t *message;
|
2020-07-11 20:30:08 +02:00
|
|
|
notmuch_bool_t is_set;
|
|
|
|
notmuch_status_t status;
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
if (!FIXNUM_P (flagv))
|
|
|
|
rb_raise (rb_eTypeError, "Flag not a Fixnum");
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2020-07-11 20:30:08 +02:00
|
|
|
status = notmuch_message_get_flag_st (message, FIX2INT (flagv), &is_set);
|
|
|
|
notmuch_rb_status_raise (status);
|
|
|
|
|
|
|
|
return is_set ? Qtrue : Qfalse;
|
2010-05-22 07:45:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-10-04 15:41:52 +02:00
|
|
|
* call-seq: MESSAGE.set_flag (flag, value) => nil
|
2010-05-22 07:45:40 +02:00
|
|
|
*
|
|
|
|
* Set a value of a flag for the email corresponding to 'message'
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_set_flag (VALUE self, VALUE flagv, VALUE valuev)
|
2010-05-22 07:45:40 +02:00
|
|
|
{
|
2010-05-26 17:54:25 +02:00
|
|
|
notmuch_message_t *message;
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
if (!FIXNUM_P (flagv))
|
|
|
|
rb_raise (rb_eTypeError, "Flag not a Fixnum");
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_message_set_flag (message, FIX2INT (flagv), RTEST (valuev));
|
2010-05-26 17:54:25 +02:00
|
|
|
|
2010-05-22 07:45:40 +02:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq: MESSAGE.date => Fixnum
|
|
|
|
*
|
|
|
|
* Get the date of 'message'
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_get_date (VALUE self)
|
2010-05-22 07:45:40 +02:00
|
|
|
{
|
2010-05-26 17:54:25 +02:00
|
|
|
notmuch_message_t *message;
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
return UINT2NUM (notmuch_message_get_date (message));
|
2010-05-22 07:45:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-10-04 15:41:52 +02:00
|
|
|
* call-seq: MESSAGE.header (name) => String
|
2010-05-22 07:45:40 +02:00
|
|
|
*
|
|
|
|
* Get the value of the specified header from 'message'
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_get_header (VALUE self, VALUE headerv)
|
2010-05-22 07:45:40 +02:00
|
|
|
{
|
|
|
|
const char *header, *value;
|
2010-05-26 17:54:25 +02:00
|
|
|
notmuch_message_t *message;
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
SafeStringValue (headerv);
|
|
|
|
header = RSTRING_PTR (headerv);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
value = notmuch_message_get_header (message, header);
|
2010-05-22 07:45:40 +02:00
|
|
|
if (!value)
|
2011-10-04 15:41:52 +02:00
|
|
|
rb_raise (notmuch_rb_eMemoryError, "Out of memory");
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
return rb_str_new2 (value);
|
2010-05-22 07:45:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq: MESSAGE.tags => TAGS
|
|
|
|
*
|
|
|
|
* Get a Notmuch::Tags enumerable for all of the tags of 'message'.
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_get_tags (VALUE self)
|
2010-05-22 07:45:40 +02:00
|
|
|
{
|
2010-05-26 17:54:25 +02:00
|
|
|
notmuch_message_t *message;
|
|
|
|
notmuch_tags_t *tags;
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
tags = notmuch_message_get_tags (message);
|
2010-05-26 17:54:25 +02:00
|
|
|
if (!tags)
|
2011-10-04 15:41:52 +02:00
|
|
|
rb_raise (notmuch_rb_eMemoryError, "Out of memory");
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2023-03-23 00:43:44 +01:00
|
|
|
return notmuch_rb_tags_get (tags);
|
2010-05-22 07:45:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-10-04 15:41:52 +02:00
|
|
|
* call-seq: MESSAGE.add_tag (tag) => true
|
2010-05-22 07:45:40 +02:00
|
|
|
*
|
|
|
|
* Add a tag to the 'message'
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_add_tag (VALUE self, VALUE tagv)
|
2010-05-22 07:45:40 +02:00
|
|
|
{
|
|
|
|
const char *tag;
|
|
|
|
notmuch_status_t ret;
|
2010-05-26 17:54:25 +02:00
|
|
|
notmuch_message_t *message;
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
SafeStringValue (tagv);
|
|
|
|
tag = RSTRING_PTR (tagv);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
ret = notmuch_message_add_tag (message, tag);
|
|
|
|
notmuch_rb_status_raise (ret);
|
2010-05-26 17:54:25 +02:00
|
|
|
|
2010-05-22 07:45:40 +02:00
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2011-10-04 15:41:52 +02:00
|
|
|
* call-seq: MESSAGE.remove_tag (tag) => true
|
2010-05-22 07:45:40 +02:00
|
|
|
*
|
|
|
|
* Remove a tag from the 'message'
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_remove_tag (VALUE self, VALUE tagv)
|
2010-05-22 07:45:40 +02:00
|
|
|
{
|
|
|
|
const char *tag;
|
|
|
|
notmuch_status_t ret;
|
2010-05-26 17:54:25 +02:00
|
|
|
notmuch_message_t *message;
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
SafeStringValue (tagv);
|
|
|
|
tag = RSTRING_PTR (tagv);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
ret = notmuch_message_remove_tag (message, tag);
|
|
|
|
notmuch_rb_status_raise (ret);
|
2010-05-26 17:54:25 +02:00
|
|
|
|
2010-05-22 07:45:40 +02:00
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq: MESSAGE.remove_all_tags => true
|
|
|
|
*
|
|
|
|
* Remove all tags of the 'message'
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_remove_all_tags (VALUE self)
|
2010-05-22 07:45:40 +02:00
|
|
|
{
|
|
|
|
notmuch_status_t ret;
|
2010-05-26 17:54:25 +02:00
|
|
|
notmuch_message_t *message;
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
ret = notmuch_message_remove_all_tags (message);
|
|
|
|
notmuch_rb_status_raise (ret);
|
2010-05-26 17:54:25 +02:00
|
|
|
|
2010-05-22 07:45:40 +02:00
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
2011-01-10 15:02:43 +01:00
|
|
|
/*
|
|
|
|
* call-seq: MESSAGE.maildir_flags_to_tags => true
|
|
|
|
*
|
2011-10-04 15:41:52 +02:00
|
|
|
* Add/remove tags according to maildir flags in the message filename (s)
|
2011-01-10 15:02:43 +01:00
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_maildir_flags_to_tags (VALUE self)
|
2011-01-10 15:02:43 +01:00
|
|
|
{
|
|
|
|
notmuch_status_t ret;
|
|
|
|
notmuch_message_t *message;
|
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2011-01-10 15:02:43 +01:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
ret = notmuch_message_maildir_flags_to_tags (message);
|
|
|
|
notmuch_rb_status_raise (ret);
|
2011-01-10 15:02:43 +01:00
|
|
|
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq: MESSAGE.tags_to_maildir_flags => true
|
|
|
|
*
|
2011-10-04 15:41:52 +02:00
|
|
|
* Rename message filename (s) to encode tags as maildir flags
|
2011-01-10 15:02:43 +01:00
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_tags_to_maildir_flags (VALUE self)
|
2011-01-10 15:02:43 +01:00
|
|
|
{
|
|
|
|
notmuch_status_t ret;
|
|
|
|
notmuch_message_t *message;
|
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2011-01-10 15:02:43 +01:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
ret = notmuch_message_tags_to_maildir_flags (message);
|
|
|
|
notmuch_rb_status_raise (ret);
|
2011-01-10 15:02:43 +01:00
|
|
|
|
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
2010-05-22 07:45:40 +02:00
|
|
|
/*
|
|
|
|
* call-seq: MESSAGE.freeze => true
|
|
|
|
*
|
|
|
|
* Freeze the 'message'
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_freeze (VALUE self)
|
2010-05-22 07:45:40 +02:00
|
|
|
{
|
|
|
|
notmuch_status_t ret;
|
2010-05-26 17:54:25 +02:00
|
|
|
notmuch_message_t *message;
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
ret = notmuch_message_freeze (message);
|
|
|
|
notmuch_rb_status_raise (ret);
|
2010-05-26 17:54:25 +02:00
|
|
|
|
2010-05-22 07:45:40 +02:00
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* call-seq: MESSAGE.thaw => true
|
|
|
|
*
|
|
|
|
* Thaw a 'message'
|
|
|
|
*/
|
|
|
|
VALUE
|
2011-10-04 15:41:52 +02:00
|
|
|
notmuch_rb_message_thaw (VALUE self)
|
2010-05-22 07:45:40 +02:00
|
|
|
{
|
|
|
|
notmuch_status_t ret;
|
2010-05-26 17:54:25 +02:00
|
|
|
notmuch_message_t *message;
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
Data_Get_Notmuch_Message (self, message);
|
2010-05-22 07:45:40 +02:00
|
|
|
|
2011-10-04 15:41:52 +02:00
|
|
|
ret = notmuch_message_thaw (message);
|
|
|
|
notmuch_rb_status_raise (ret);
|
2010-05-26 17:54:25 +02:00
|
|
|
|
2010-05-22 07:45:40 +02:00
|
|
|
return Qtrue;
|
|
|
|
}
|