Re: [PATCH] python: add bindings for notmuch_message_get_propert(y/ies)

2018-05-02 Thread meskio
Quoting David Bremner (2018-05-02 02:08:26)
> Ruben Pollan <mes...@sindominio.net> writes:
> 
> > Message.get_property (prop) returns a string with the value of the property 
> > and
> > Message.get_properties (prop, exact=False) yields key, value pairs
> > ---
> >  bindings/python/docs/source/message.rst |  4 ++
> >  bindings/python/notmuch/globals.py  |  5 +++
> >  bindings/python/notmuch/message.py  | 80 
> > -
> >  3 files changed, 88 insertions(+), 1 deletion(-)
> >
> 
> This version passes the first test (after fixing the format, as you
> noted), but it looks like get_properties is returning pairs of
> bytestrings.
> 
> FAIL   [15] msg.get_properties (python)
> --- T610-message-property.16.EXPECTED   2018-05-02 00:02:11.160028179 
> +
> +++ T610-message-property.16.OUTPUT 2018-05-02 00:02:11.164028171 
> +
> @@ -1,4 +1,4 @@
> -testkey1 = alice
> -testkey1 = bob
> -testkey1 = testvalue1
> -testkey1 = testvalue2
> +b'testkey1' = b'alice'
> +b'testkey1' = b'bob'
> +b'testkey1' = b'testvalue1'
> +b'testkey1' = b'testvalue2'
> 
> I don't _think_ that's what we want. We had some discussion before and
> decided that it was reasonable to only support utf-8 properties, so
> converting to strings should be OK?

I added the 'decode("utf-8")' to get_property but I didn't to get_properties.  
Next patch fixes it.

-- 
meskio | http://meskio.net/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 My contact info: http://meskio.net/crypto.txt
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Nos vamos a Croatan.


signature.asc
Description: signature
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] python: add bindings for notmuch_message_get_propert(y/ies)

2018-05-01 Thread meskio
Quoting David Bremner (2018-05-01 15:06:38)
> running the test below, I get
> 
> Traceback (most recent call last):
>   File "", line 4, in 
>   File 
> "/home/bremner/software/upstream/notmuch/bindings/python/notmuch/message.py", 
> line 480, in get_property
> value = c_char_p("")
> TypeError: bytes or integer address expected instead of str instance

Ups, I was using python2 to test it. I see it doesn't work with python three.  
I'll send an update.

> diff --git a/test/T610-message-property.sh b/test/T610-message-property.sh
> index 74b3f5a1..f7220565 100755
> --- a/test/T610-message-property.sh
> +++ b/test/T610-message-property.sh
> @@ -89,6 +89,18 @@ testkey2 = NULL
>  EOF
>  test_expect_equal_file EXPECTED OUTPUT
>  
> +test_begin_subtest "msg.get_property (python)"
> +test_python <<'EOF'
> +import notmuch
> +db = notmuch.Database(mode=notmuch.Database.MODE.READ_WRITE)
> +msg = db.find_message("4efc743a.3060...@april.org")
> +print("testkey1[1] = %s\n".format(msg.get_property("testkey1")))

I think this should be (notice the {0} instead of %s):
print("testkey1[1] = {0}".format(msg.get_property("testkey1")))


-- 
meskio | http://meskio.net/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 My contact info: http://meskio.net/crypto.txt
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Nos vamos a Croatan.


signature.asc
Description: signature
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] python: add bindings for notmuch_message_get_propert(y/ies)

2018-04-27 Thread meskio
Quoting David Bremner (2017-12-23 16:59:51)
> Ruben Pollan <mes...@sindominio.net> writes:
> > +
> > +def get_properties(self, prop="", exact=False):
> 
> As far as I understand, you also need to update docs/source/message.rst
> so that your new methods are documented in the sphinx docs.
> 
> > +""" Get the properties for *message*, returning
> > +notmuch_message_properties_t object which can be used to iterate
> > +over all properties.
> 
> This seeems to be wrong (or at last confusing) for the python bindings.
> 
> > +
> > +:param prop: The name of the property to get. Otherwise it will 
> > return
> > + the full list of properties of the message.
> > +:param exact: if True, require exact match with key. Otherwise
> > +  treat as prefix.
> > +:returns: A dictionary with the property names and values {key: 
> > value}
> > +:raises: :exc:`NotInitializedError` if message has not been
> > + initialized
> > +"""
> > +if not self._msg:
> > +raise NotInitializedError()
> > +
> > +properties_dict = {}
> > +properties = Message._get_properties(self._msg, prop, exact)
> 
> Now that the database.get_configs method is merged, I'd prefer to be 
> consistent
> with that, and define a generator that yields key/value pairs. It's easy
> enough for someone to use a dictionary comprehension to get a dict from
> that if they want it.  Sorry to be making extra work for you.

Good to me, I'm sending an update with all this fixed.

Sorry for letting it hung for so long.

-- 
meskio | http://meskio.net/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 My contact info: http://meskio.net/crypto.txt
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Nos vamos a Croatan.


signature.asc
Description: signature
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] python: add bindings for notmuch_message_get_propert(y/ies)

2017-11-29 Thread meskio
Quoting Daniel Kahn Gillmor (2017-11-29 02:57:24)
> On Tue 2017-11-28 23:46:11 +0100, Ruben Pollan wrote:
> > Message.get_property (prop) returns a string with the value of the property 
> > and
> > Message.get_properties (prop, exact=False) returns a list [(key, value)]
> 
> This looks like a sensible approach to me.  I'd be curious to hear what
> others think of this.
> 
> In considering the API design space here, it occurs to me that it might
> be more pythonic for get_properties to return a dict like:
> 
>{ key: [ value, … ], key: [ value, … ] }
> 
> Any reason you chose one over the other?  My python-fu is shallow, so
> please don't take my aesthetic guesswork as authoritative; but i'm
> imagining a user wanting to grab a bunch of properties and then easily
> access them by key, and the dict seems like the simple way to do that.

Yes, the dict is more pythonic. I thought about it, I went for the tuples it 
was 
simpler to implement (and use in my use case). But giving a second thought it 
makes more sense to do a dict.

> Also, does get_properties() work with prop=None to fetch all properties?
> if so, maybe that should be the default?

I didn't thought about that, but you are right, with prop="" you get the full 
list of properties of the message. Nice, let's put it as default value.

-- 
meskio | http://meskio.net/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 My contact info: http://meskio.net/crypto.txt
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Nos vamos a Croatan.


signature.asc
Description: signature
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] python: add bindings for notmuch_message_get_propert(y/ies)

2017-11-28 Thread meskio
Quoting Daniel Kahn Gillmor (2017-11-17 10:03:09)
> On Wed 2017-11-15 23:29:54 +0100, Ruben Pollan wrote:
> > Message.get_property (prop) returns a string with the value of the property.
> 
> Upon review, this is actually insufficient for making robust use of the
> session-key series :(
> 
> In particular, it only returns the first value for the session key
> returned.

See the last patch. I added the implementation of get_properties (and I use it 
in my session-key branch of alot). Hopefully this solves the problem.

> In the session-key series, i work around this by simply trying each
> session key against an encrypted part until i find one that works. It
> would be "cleaner" (more principled) to somehow associate each session
> key with the part(s) of the message file(s) that it is capable of
> decrypting, but that's a lot of bookkeeping -- i think it's actually
> "cleaner" (less code, less computation in the standard case) to just
> take the current approach.

Fair enough for me, I'm copying this approach in alot as well.

-- 
meskio | http://meskio.net/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 My contact info: http://meskio.net/crypto.txt
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Nos vamos a Croatan.


signature.asc
Description: signature
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH] python: add bindings for notmuch_message_get_property

2017-11-15 Thread meskio
Quoting Ruben Pollan (2017-11-15 23:29:54)
> Message.get_property (prop) returns a string with the value of the property.

I only implemented get_property as is the only one I need to add support for 
session keys in alot (https://github.com/meskio/alot/tree/session-key). From 
the 
point of view of the MUAs I don't see much interest in exporting all the other 
functions to modify properties. But I was not sure if adding them to have the 
whole set of message property functions in python.

-- 
meskio | http://meskio.net/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 My contact info: http://meskio.net/crypto.txt
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Nos vamos a Croatan.


signature.asc
Description: signature
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


Re: Stashed session keys

2017-11-15 Thread meskio
Quoting Daniel Kahn Gillmor (2017-10-25 08:51:45)
> Now that cleartext indexing is merged, let's add the ability to stash
> session keys!

Nice feature. I'm using it and it works fine. I notice some speed up, improving 
the painfulness of reading long encrypted threads in alot. And I like to don't 
be able to have around my old private keys.

I implemented some support for it in alot (using the patch I just sent adding 
notmuch_message_get_property to the python binding):
https://github.com/meskio/alot/tree/session-key

Thanks for the work.

-- 
meskio | http://meskio.net/
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 My contact info: http://meskio.net/crypto.txt
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Nos vamos a Croatan.


signature.asc
Description: signature
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] Including 'unread' tag to mails without maildir flags

2010-11-19 Thread meskio
From: Ruben Pollan mes...@sindominio.net

Some mail fetchers, like fetchmail, leaves the email without ':2,' at the end of
the filename. Notmuch didn't detect this emails as maildir, it didn't add the
maildir flags to them.

Now it detects if a mail is in a maildir by the directory structure, and add its
maildir flags correctly.
---
 lib/message.cc |   87 +---
 1 files changed, 45 insertions(+), 42 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index 225b7e9..996c1df 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -854,6 +854,47 @@ notmuch_message_remove_tag (notmuch_message_t *message, 
const char *tag)
 return NOTMUCH_STATUS_SUCCESS;
 }
 
+/* Is the given filename within a maildir directory?
+ *
+ * Specifically, is the final directory component of 'filename' either
+ * cur or new. If so, return a pointer to that final directory
+ * component within 'filename'. If not, return NULL.
+ *
+ * A non-NULL return value is guaranteed to be a valid string pointer
+ * pointing to the characters new/ or cur/, (but not
+ * NUL-terminated).
+ */
+static const char *
+_filename_is_in_maildir (const char *filename)
+{
+const char *slash, *dir = NULL;
+
+/* Find the last '/' separating directory from filename. */
+slash = strrchr (filename, '/');
+if (slash == NULL)
+   return NULL;
+
+/* Jump back 4 characters to where the previous '/' will be if the
+ * directory is named cur or new. */
+if (slash - filename  4)
+   return NULL;
+
+slash -= 4;
+
+if (*slash != '/')
+   return NULL;
+
+dir = slash + 1;
+
+if (STRNCMP_LITERAL (dir, cur/) == 0 ||
+   STRNCMP_LITERAL (dir, new/) == 0)
+{
+   return dir;
+}
+
+return NULL;
+}
+
 notmuch_status_t
 notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)
 {
@@ -871,11 +912,14 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t 
*message)
 {
filename = notmuch_filenames_get (filenames);
 
+   if (! _filename_is_in_maildir(filename))
+   continue;
+   seen_maildir_info = 1;
+
flags = strstr (filename, :2,);
if (! flags)
continue;
 
-   seen_maildir_info = 1;
flags += 3;
 
combined_flags = talloc_strdup_append (combined_flags, flags);
@@ -910,47 +954,6 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t 
*message)
 return status;
 }
 
-/* Is the given filename within a maildir directory?
- *
- * Specifically, is the final directory component of 'filename' either
- * cur or new. If so, return a pointer to that final directory
- * component within 'filename'. If not, return NULL.
- *
- * A non-NULL return value is guaranteed to be a valid string pointer
- * pointing to the characters new/ or cur/, (but not
- * NUL-terminated).
- */
-static const char *
-_filename_is_in_maildir (const char *filename)
-{
-const char *slash, *dir = NULL;
-
-/* Find the last '/' separating directory from filename. */
-slash = strrchr (filename, '/');
-if (slash == NULL)
-   return NULL;
-
-/* Jump back 4 characters to where the previous '/' will be if the
- * directory is named cur or new. */
-if (slash - filename  4)
-   return NULL;
-
-slash -= 4;
-
-if (*slash != '/')
-   return NULL;
-
-dir = slash + 1;
-
-if (STRNCMP_LITERAL (dir, cur/) == 0 ||
-   STRNCMP_LITERAL (dir, new/) == 0)
-{
-   return dir;
-}
-
-return NULL;
-}
-
 /* From the set of tags on 'message' and the flag2tag table, compute a
  * set of maildir-flag actions to be taken, (flags that should be
  * either set or cleared).
-- 
1.7.1

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[notmuch] [PATCH 2/2] Added regress option to messages iterator

2009-12-08 Thread meskio
From: Ruben Pollan mes...@sindominio.net

Added the functions notmuch_messages_regress and notmuch_messages_is_first to
notmuch library. With them is possible to iterate backwards on messages.

* notmuch_messages_regress do the opposite than notmuch_messages_advance,
  getting the messages iterator one position backwards.

* notmuch_messages_is_first return TRUE if the iterator is in the first
  message.
---
 lib/messages.c|   27 +++
 lib/notmuch-private.h |7 +++
 lib/notmuch.h |8 
 lib/query.cc  |   24 
 4 files changed, 66 insertions(+), 0 deletions(-)

diff --git a/lib/messages.c b/lib/messages.c
index 5414f87..2c28738 100644
--- a/lib/messages.c
+++ b/lib/messages.c
@@ -90,6 +90,7 @@ _notmuch_messages_create (notmuch_message_list_t *list)
 
 messages-is_of_list_type = TRUE;
 messages-iterator = list-head;
+messages-previous_node = NULL;
 
 return messages;
 }
@@ -121,6 +122,18 @@ notmuch_messages_has_more (notmuch_messages_t *messages)
 return (messages-iterator != NULL);
 }
 
+notmuch_bool_t
+notmuch_messages_is_first (notmuch_messages_t *messages)
+{
+if (messages == NULL)
+   return TRUE;
+
+if (! messages-is_of_list_type)
+   return _notmuch_mset_messages_is_first (messages);
+
+return (messages-previous_node == NULL);
+}
+
 notmuch_message_t *
 notmuch_messages_get (notmuch_messages_t *messages)
 {
@@ -142,10 +155,24 @@ notmuch_messages_advance (notmuch_messages_t *messages)
 if (messages-iterator == NULL)
return;
 
+messages-previous_node = messages-iterator;
 messages-iterator = messages-iterator-next;
 }
 
 void
+notmuch_messages_regress (notmuch_messages_t *messages)
+{
+if (! messages-is_of_list_type)
+   return _notmuch_mset_messages_regress (messages);
+
+if (messages-previous_node == NULL)
+   return;
+
+messages-iterator = messages-previous_node;
+messages-previous_node = messages-iterator-prev;
+}
+
+void
 notmuch_messages_destroy (notmuch_messages_t *messages)
 {
 talloc_free (messages);
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index 133ed0e..5852c00 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -299,6 +299,7 @@ typedef struct _notmuch_message_list {
  */
 struct _notmuch_messages {
 notmuch_bool_t is_of_list_type;
+notmuch_message_node_t *previous_node;
 notmuch_message_node_t *iterator;
 };
 
@@ -321,12 +322,18 @@ _notmuch_messages_create (notmuch_message_list_t *list);
 notmuch_bool_t
 _notmuch_mset_messages_has_more (notmuch_messages_t *messages);
 
+notmuch_bool_t
+_notmuch_mset_messages_is_first (notmuch_messages_t *messages);
+
 notmuch_message_t *
 _notmuch_mset_messages_get (notmuch_messages_t *messages);
 
 void
 _notmuch_mset_messages_advance (notmuch_messages_t *messages);
 
+void
+_notmuch_mset_messages_regress (notmuch_messages_t *messages);
+
 /* message.cc */
 
 void
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 60834fb..69bd98a 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -604,6 +604,10 @@ notmuch_thread_destroy (notmuch_thread_t *thread);
 notmuch_bool_t
 notmuch_messages_has_more (notmuch_messages_t *messages);
 
+/* Is the given notmuch_messages_t object on the first message */
+notmuch_bool_t
+notmuch_messages_is_first (notmuch_messages_t *messages);
+
 /* Get the current message from 'messages' as a notmuch_message_t.
  *
  * Note: The returned message belongs to 'messages' and has a lifetime
@@ -626,6 +630,10 @@ notmuch_messages_get (notmuch_messages_t *messages);
 void
 notmuch_messages_advance (notmuch_messages_t *messages);
 
+/* Regress the 'messages' iterator to the previous result. */
+void
+notmuch_messages_regress (notmuch_messages_t *messages);
+
 /* Destroy a notmuch_messages_t object.
  *
  * It's not strictly necessary to call this function. All memory from
diff --git a/lib/query.cc b/lib/query.cc
index 9106b92..94a6860 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -35,6 +35,7 @@ typedef struct _notmuch_mset_messages {
 notmuch_messages_t base;
 notmuch_database_t *notmuch;
 Xapian::MSetIterator iterator;
+Xapian::MSetIterator iterator_begin;
 Xapian::MSetIterator iterator_end;
 } notmuch_mset_messages_t;
 
@@ -86,6 +87,7 @@ static int
 _notmuch_messages_destructor (notmuch_mset_messages_t *messages)
 {
 messages-iterator.~MSetIterator ();
+messages-iterator_begin.~MSetIterator ();
 messages-iterator_end.~MSetIterator ();
 
 return 0;
@@ -108,6 +110,7 @@ notmuch_query_search_messages (notmuch_query_t *query)
messages-base.iterator = NULL;
messages-notmuch = notmuch;
new (messages-iterator) Xapian::MSetIterator ();
+   new (messages-iterator_begin) Xapian::MSetIterator ();
new (messages-iterator_end) Xapian::MSetIterator ();
 
talloc_set_destructor (messages, _notmuch_messages_destructor);
@@ -155,6 +158,7 @@ notmuch_query_search_messages