unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
blob 0d83567c531529a41f6fca910f3053e3d13ed9e7 7887 bytes (raw)
name: bindings/ruby/message.c 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
 
/* The Ruby interface to the notmuch mail library
 *
 * Copyright © 2010, 2011 Ali Polatel
 *
 * 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
 * along with this program.  If not, see https://www.gnu.org/licenses/ .
 *
 * Author: Ali Polatel <alip@exherbo.org>
 */

#include "defs.h"

/*
 * call-seq: MESSAGE.destroy! => nil
 *
 * Destroys the message, freeing all resources allocated for it.
 */
VALUE
notmuch_rb_message_destroy (VALUE self)
{
    notmuch_rb_object_destroy (self, &notmuch_rb_message_type);

    return Qnil;
}

/*
 * call-seq: MESSAGE.message_id => String
 *
 * Get the message ID of 'message'.
 */
VALUE
notmuch_rb_message_get_message_id (VALUE self)
{
    const char *msgid;
    notmuch_message_t *message;

    Data_Get_Notmuch_Message (self, message);

    msgid = notmuch_message_get_message_id (message);

    return rb_str_new2 (msgid);
}

/*
 * call-seq: MESSAGE.thread_id => String
 *
 * Get the thread ID of 'message'.
 */
VALUE
notmuch_rb_message_get_thread_id (VALUE self)
{
    const char *tid;
    notmuch_message_t *message;

    Data_Get_Notmuch_Message (self, message);

    tid = notmuch_message_get_thread_id (message);

    return rb_str_new2 (tid);
}

/*
 * call-seq: MESSAGE.replies => MESSAGES
 *
 * Get a Notmuch::Messages enumerable for all of the replies to 'message'.
 */
VALUE
notmuch_rb_message_get_replies (VALUE self)
{
    notmuch_messages_t *messages;
    notmuch_message_t *message;

    Data_Get_Notmuch_Message (self, message);

    messages = notmuch_message_get_replies (message);

    return Data_Wrap_Notmuch_Object (notmuch_rb_cMessages, &notmuch_rb_messages_type, messages);
}

/*
 * call-seq: MESSAGE.filename => String
 *
 * Get a filename for the email corresponding to 'message'
 */
VALUE
notmuch_rb_message_get_filename (VALUE self)
{
    const char *fname;
    notmuch_message_t *message;

    Data_Get_Notmuch_Message (self, message);

    fname = notmuch_message_get_filename (message);

    return rb_str_new2 (fname);
}

/*
 * call-seq: MESSAGE.filenames => FILENAMES
 *
 * Get all filenames for the email corresponding to MESSAGE.
 */
VALUE
notmuch_rb_message_get_filenames (VALUE self)
{
    notmuch_filenames_t *fnames;
    notmuch_message_t *message;

    Data_Get_Notmuch_Message (self, message);

    fnames = notmuch_message_get_filenames (message);

    return notmuch_rb_filenames_get (fnames);
}

/*
 * call-seq: MESSAGE.get_flag (flag) => true or false
 *
 * Get a value of a flag for the email corresponding to 'message'
 */
VALUE
notmuch_rb_message_get_flag (VALUE self, VALUE flagv)
{
    notmuch_message_t *message;
    notmuch_bool_t is_set;
    notmuch_status_t status;

    Data_Get_Notmuch_Message (self, message);

    if (!FIXNUM_P (flagv))
	rb_raise (rb_eTypeError, "Flag not a Fixnum");

    status = notmuch_message_get_flag_st (message, FIX2INT (flagv), &is_set);
    notmuch_rb_status_raise (status);

    return is_set ? Qtrue : Qfalse;
}

/*
 * call-seq: MESSAGE.set_flag (flag, value) => nil
 *
 * Set a value of a flag for the email corresponding to 'message'
 */
VALUE
notmuch_rb_message_set_flag (VALUE self, VALUE flagv, VALUE valuev)
{
    notmuch_message_t *message;

    Data_Get_Notmuch_Message (self, message);

    if (!FIXNUM_P (flagv))
	rb_raise (rb_eTypeError, "Flag not a Fixnum");

    notmuch_message_set_flag (message, FIX2INT (flagv), RTEST (valuev));

    return Qnil;
}

/*
 * call-seq: MESSAGE.date => Fixnum
 *
 * Get the date of 'message'
 */
VALUE
notmuch_rb_message_get_date (VALUE self)
{
    notmuch_message_t *message;

    Data_Get_Notmuch_Message (self, message);

    return UINT2NUM (notmuch_message_get_date (message));
}

/*
 * call-seq: MESSAGE.header (name) => String
 *
 * Get the value of the specified header from 'message'
 */
VALUE
notmuch_rb_message_get_header (VALUE self, VALUE headerv)
{
    const char *header, *value;
    notmuch_message_t *message;

    Data_Get_Notmuch_Message (self, message);

    SafeStringValue (headerv);
    header = RSTRING_PTR (headerv);

    value = notmuch_message_get_header (message, header);
    if (!value)
	rb_raise (notmuch_rb_eMemoryError, "Out of memory");

    return rb_str_new2 (value);
}

/*
 * call-seq: MESSAGE.tags => TAGS
 *
 * Get a Notmuch::Tags enumerable for all of the tags of 'message'.
 */
VALUE
notmuch_rb_message_get_tags (VALUE self)
{
    notmuch_message_t *message;
    notmuch_tags_t *tags;

    Data_Get_Notmuch_Message (self, message);

    tags = notmuch_message_get_tags (message);
    if (!tags)
	rb_raise (notmuch_rb_eMemoryError, "Out of memory");

    return Data_Wrap_Notmuch_Object (notmuch_rb_cTags, &notmuch_rb_tags_type, tags);
}

/*
 * call-seq: MESSAGE.add_tag (tag) => true
 *
 * Add a tag to the 'message'
 */
VALUE
notmuch_rb_message_add_tag (VALUE self, VALUE tagv)
{
    const char *tag;
    notmuch_status_t ret;
    notmuch_message_t *message;

    Data_Get_Notmuch_Message (self, message);

    SafeStringValue (tagv);
    tag = RSTRING_PTR (tagv);

    ret = notmuch_message_add_tag (message, tag);
    notmuch_rb_status_raise (ret);

    return Qtrue;
}

/*
 * call-seq: MESSAGE.remove_tag (tag) => true
 *
 * Remove a tag from the 'message'
 */
VALUE
notmuch_rb_message_remove_tag (VALUE self, VALUE tagv)
{
    const char *tag;
    notmuch_status_t ret;
    notmuch_message_t *message;

    Data_Get_Notmuch_Message (self, message);

    SafeStringValue (tagv);
    tag = RSTRING_PTR (tagv);

    ret = notmuch_message_remove_tag (message, tag);
    notmuch_rb_status_raise (ret);

    return Qtrue;
}

/*
 * call-seq: MESSAGE.remove_all_tags => true
 *
 * Remove all tags of the 'message'
 */
VALUE
notmuch_rb_message_remove_all_tags (VALUE self)
{
    notmuch_status_t ret;
    notmuch_message_t *message;

    Data_Get_Notmuch_Message (self, message);

    ret = notmuch_message_remove_all_tags (message);
    notmuch_rb_status_raise (ret);

    return Qtrue;
}

/*
 * call-seq: MESSAGE.maildir_flags_to_tags => true
 *
 * Add/remove tags according to maildir flags in the message filename (s)
 */
VALUE
notmuch_rb_message_maildir_flags_to_tags (VALUE self)
{
    notmuch_status_t ret;
    notmuch_message_t *message;

    Data_Get_Notmuch_Message (self, message);

    ret = notmuch_message_maildir_flags_to_tags (message);
    notmuch_rb_status_raise (ret);

    return Qtrue;
}

/*
 * call-seq: MESSAGE.tags_to_maildir_flags => true
 *
 * Rename message filename (s) to encode tags as maildir flags
 */
VALUE
notmuch_rb_message_tags_to_maildir_flags (VALUE self)
{
    notmuch_status_t ret;
    notmuch_message_t *message;

    Data_Get_Notmuch_Message (self, message);

    ret = notmuch_message_tags_to_maildir_flags (message);
    notmuch_rb_status_raise (ret);

    return Qtrue;
}

/*
 * call-seq: MESSAGE.freeze => true
 *
 * Freeze the 'message'
 */
VALUE
notmuch_rb_message_freeze (VALUE self)
{
    notmuch_status_t ret;
    notmuch_message_t *message;

    Data_Get_Notmuch_Message (self, message);

    ret = notmuch_message_freeze (message);
    notmuch_rb_status_raise (ret);

    return Qtrue;
}

/*
 * call-seq: MESSAGE.thaw => true
 *
 * Thaw a 'message'
 */
VALUE
notmuch_rb_message_thaw (VALUE self)
{
    notmuch_status_t ret;
    notmuch_message_t *message;

    Data_Get_Notmuch_Message (self, message);

    ret = notmuch_message_thaw (message);
    notmuch_rb_status_raise (ret);

    return Qtrue;
}

debug log:

solving 0d83567c ...
found 0d83567c in https://yhetil.org/notmuch/20230327215942.13286-2-felipe.contreras@gmail.com/
found f45c95cc in https://yhetil.org/notmuch.git/
preparing index
index prepared:
100644 f45c95cc5051d8475920c5a59bf07706e829e0be	bindings/ruby/message.c

applying [1/1] https://yhetil.org/notmuch/20230327215942.13286-2-felipe.contreras@gmail.com/
diff --git a/bindings/ruby/message.c b/bindings/ruby/message.c
index f45c95cc..0d83567c 100644

Checking patch bindings/ruby/message.c...
Applied patch bindings/ruby/message.c cleanly.

index at:
100644 0d83567c531529a41f6fca910f3053e3d13ed9e7	bindings/ruby/message.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).