[notmuch] [PATCH] Make the date parser nicer

2010-01-22 Thread Sebastian Spaeth
On Fri, 22 Jan 2010 16:26:11 +0100, Sebastian Spaeth  
wrot> +  if (begin.size() == 8) {
> +   int no_items;
> +   no_items = sscanf(begin.c_str(), "%4i%2i%2i", , , );
> +   if (no_items != 3)
> + return Xapian::BAD_VALUENO;

Also I have found that my sscanf skills are sourly lacking:
a date of 20060108 will lead to 2006 1 0 for (year, month, day)

I bet someone knows a nice way to parse those values in a good way.

Sebastian


[notmuch] [PATCH] Make the date parser nicer

2010-01-22 Thread Sebastian Spaeth

Please find in the previous mail attached my patch (against my current
all-feature branch, but should pretty much apply to current master too).
It is a proof-of-concept to make the date parser nicer. The following 
searches work with this code:

notmuch show...
... date:2001..2010 (from beginning of 2001 until end of 2010)
... date:20011201..200506 (from 1001-12-01 until 2005-06-31

The code will pretty surely need some cleaning up, as I can hardly code
C, not to speak of C++. But at least it works and it is not very
intrusive.

(Ps. now that I think of it, I always use day 31 as last day, which is
surely wrong, it also still accepts some obviously wrong dates like
20040231)

We could also think about using a xapian DateValueRangeParser to do
that, but that would require saving the timestamp as MMDD in the
database (which we probably do not want).

Feedback welcome,
Sebastian


[notmuch] [PATCH] Make the date parser nicer

2010-01-22 Thread Sebastian Spaeth
Currently we have to enter mail dates as timestamps. This approach does 2 
things: it requires the prefix 'date:' and it allows timestamps to be specified 
as , MM or MMDD. So a notmuch show date:2005..20060512 will find 
all mails from 2005-01-01 until 2006-05-12. The code is probably not in a 
proper location yet and needs to be shoved around by someone more knowledgable 
than me. My C++ skills are somewhat,... lacking...

Signed-off-by: Sebastian Spaeth 
---
 lib/database.cc |   94 ++-
 1 files changed, 93 insertions(+), 1 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 5b12320..102a6ff 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -494,6 +494,97 @@ _notmuch_database_ensure_writable (notmuch_database_t 
*notmuch)
 return NOTMUCH_STATUS_SUCCESS;
 }

+struct MaildateValueRangeProcessor : public Xapian::ValueRangeProcessor {
+MaildateValueRangeProcessor() {}
+
+Xapian::valueno operator()(std::string , std::string ) {
+if (begin.substr(0, 5) != "date:")
+return Xapian::BAD_VALUENO;
+begin.erase(0, 5);
+
+   // Parse the begin date to time_t
+   struct tm *timeinfo;
+   time_t begintime, endtime;
+   //const char * startptr;
+   int year, month, day;
+
+   if (begin.size() == 8) {
+ int no_items;
+ no_items = sscanf(begin.c_str(), "%4i%2i%2i", , , );
+ if (no_items != 3)
+   return Xapian::BAD_VALUENO;
+   } else if (begin.size() == 6) {
+ int no_items;
+ day = 1;
+ no_items = sscanf(begin.c_str(), "%4i%2i", , );
+ if (no_items != 2)
+   return Xapian::BAD_VALUENO;
+   } else if (begin.size() == 4) {
+ int no_items;
+ day = 1;
+ month = 1;
+ no_items = sscanf(begin.c_str(), "%4i", );
+ if (no_items != 1)
+   return Xapian::BAD_VALUENO;
+   } else {
+ // no expected time format
+ return Xapian::BAD_VALUENO;
+   }
+
+   begintime = time(NULL);
+   timeinfo = localtime(  );
+   timeinfo -> tm_year = year - 1900;
+   timeinfo -> tm_mon = month - 1;
+   fprintf (stderr, "Startdate %d %d %d\n",year,month,day);
+   timeinfo -> tm_mday = day;
+   begintime = mktime ( timeinfo );
+
+   if (begintime == -1)
+ // no valid time format
+ return Xapian::BAD_VALUENO;
+
+   if (end.size() == 8) {
+ int no_items;
+ no_items = sscanf(end.c_str(), "%4i%2i%2i", , , );
+ if (no_items != 3)
+   return Xapian::BAD_VALUENO;
+   } else if (end.size() == 6) {
+ int no_items;
+ day = 31;
+ no_items = sscanf(end.c_str(), "%4i%2i", , );
+ if (no_items != 2)
+   return Xapian::BAD_VALUENO;
+   } else if (end.size() == 4) {
+ int no_items;
+ day = 31;
+ month = 12;
+ no_items = sscanf(end.c_str(), "%4i", );
+ if (no_items != 1)
+   return Xapian::BAD_VALUENO;
+   } else {
+ // no expected time format
+ return Xapian::BAD_VALUENO;
+   }
+
+   timeinfo = localtime(  );
+   timeinfo -> tm_year = year - 1900;
+   timeinfo -> tm_mon = month - 1;
+   fprintf (stderr, "Enddate %d %d %d\n",year,month,day);
+   timeinfo -> tm_mday = day;
+   endtime = mktime ( timeinfo );
+   //XXX: plus 1 day to make the last day inclusive??
+
+   if (endtime == -1)
+ // no valid time format
+ return Xapian::BAD_VALUENO;
+   
+   begin.assign(Xapian::sortable_serialise(begintime));
+   end.assign(Xapian::sortable_serialise(endtime));
+
+return NOTMUCH_VALUE_TIMESTAMP;
+}
+};
+
 notmuch_database_t *
 notmuch_database_open (const char *path,
   notmuch_database_mode_t mode)
@@ -570,7 +661,8 @@ notmuch_database_open (const char *path,
notmuch->query_parser = new Xapian::QueryParser;
notmuch->term_gen = new Xapian::TermGenerator;
notmuch->term_gen->set_stemmer (Xapian::Stem ("english"));
-   notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor 
(NOTMUCH_VALUE_TIMESTAMP, "date:", true);
+   notmuch->value_range_processor = new MaildateValueRangeProcessor();
+ // (NOTMUCH_VALUE_TIMESTAMP);

notmuch->query_parser->set_default_op (Xapian::Query::OP_AND);
notmuch->query_parser->set_database (*notmuch->xapian_db);
-- 
1.6.3.3



[notmuch] [PATCH] fontify date in header

2010-01-22 Thread Jameson Rollins
The date was unfairly left out of getting pretty colors in the
notmuch-show header display.  This fixes that grave injustice.
---
 notmuch.el |8 +++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 97914f2..48c270b 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -722,7 +722,13 @@ before the delimiter marking the beginning of the body."
  (overlay-put (make-overlay (point) (re-search-forward ":"))
   'face 'message-header-name)
  (overlay-put (make-overlay (point) (re-search-forward ".*$"))
-  'face 'message-header-other)))
+  'face 'message-header-other))
+ (if (looking-at "[Dd]ate:")
+ (progn
+   (overlay-put (make-overlay (point) (re-search-forward ":"))
+'face 'message-header-name)
+   (overlay-put (make-overlay (point) (re-search-forward ".*$"))
+'face 'message-header-other

 (defun notmuch-show-markup-header (message-begin depth)
   "Buttonize and decorate faces in a message header.
-- 
1.6.5

-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 
<http://notmuchmail.org/pipermail/notmuch/attachments/20100122/2382cabe/attachment.pgp>


[notmuch] Git feature branch

2010-01-22 Thread Sebastian Spaeth
On Fri, 22 Jan 2010 09:09:30 +0100, Sebastian Spaeth  
wrote:
> On 01/20/10 21:00, micah anderson wrote:
> 
> > Cool! It would be useful if you provided thread-id's for each of these
> > so we could look them up and read more about them.
> 
> True, I'll try to include thread id-s in the future.

I have now listed all patches that I have added to my feature-branch
here. Where possible I have added mail id or the git source that i have
pulled from. The list is here:

http://trac.sspaeth.de/issue?@columns=title,status&@filter=status=6

Stuff that I carry:
- simplify "unread" tag handling in emacs UI
- refactor and improve dirs-to-ignore a bit
- Have notmuch count default to showing the total
- add a submap (on "z" for "ztash") to stash things
- When adding new messages, if they have the 'S' (seen) flag, do not add them 
to the 'unread' tag.
- 'd' should "delete" a mail

My feature-branch is still located here:
http://github.com/spaetz/notmuch-all-feature

So far things work fine for me. It would be cool if Carl would merge
(parts of?) it.

spaetz


[notmuch] Git feature branch

2010-01-22 Thread Sebastian Spaeth
On 01/20/10 21:00, micah anderson wrote:

> Cool! It would be useful if you provided thread-id's for each of these
> so we could look them up and read more about them.

True, I'll try to include thread id-s in the future.

spaetz


Re: [notmuch] Git feature branch

2010-01-22 Thread Sebastian Spaeth
On Fri, 22 Jan 2010 09:09:30 +0100, Sebastian Spaeth sebast...@sspaeth.de 
wrote:
 On 01/20/10 21:00, micah anderson wrote:
 
  Cool! It would be useful if you provided thread-id's for each of these
  so we could look them up and read more about them.
 
 True, I'll try to include thread id-s in the future.

I have now listed all patches that I have added to my feature-branch
here. Where possible I have added mail id or the git source that i have
pulled from. The list is here:

http://trac.sspaeth.de/iss...@columns=title,status@filter=statusstatus=6

Stuff that I carry:
- simplify unread tag handling in emacs UI
- refactor and improve dirs-to-ignore a bit
- Have notmuch count default to showing the total
- add a submap (on z for ztash) to stash things
- When adding new messages, if they have the 'S' (seen) flag, do not add them 
to the 'unread' tag.
- 'd' should delete a mail

My feature-branch is still located here:
http://github.com/spaetz/notmuch-all-feature

So far things work fine for me. It would be cool if Carl would merge
(parts of?) it.

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


[notmuch] [PATCH] Make the date parser nicer

2010-01-22 Thread Sebastian Spaeth
Currently we have to enter mail dates as timestamps. This approach does 2 
things: it requires the prefix 'date:' and it allows timestamps to be specified 
as , MM or MMDD. So a notmuch show date:2005..20060512 will find 
all mails from 2005-01-01 until 2006-05-12. The code is probably not in a 
proper location yet and needs to be shoved around by someone more knowledgable 
than me. My C++ skills are somewhat,... lacking...

Signed-off-by: Sebastian Spaeth sebast...@sspaeth.de
---
 lib/database.cc |   94 ++-
 1 files changed, 93 insertions(+), 1 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 5b12320..102a6ff 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -494,6 +494,97 @@ _notmuch_database_ensure_writable (notmuch_database_t 
*notmuch)
 return NOTMUCH_STATUS_SUCCESS;
 }
 
+struct MaildateValueRangeProcessor : public Xapian::ValueRangeProcessor {
+MaildateValueRangeProcessor() {}
+
+Xapian::valueno operator()(std::string begin, std::string end) {
+if (begin.substr(0, 5) != date:)
+return Xapian::BAD_VALUENO;
+begin.erase(0, 5);
+
+   // Parse the begin date to time_t
+   struct tm *timeinfo;
+   time_t begintime, endtime;
+   //const char * startptr;
+   int year, month, day;
+
+   if (begin.size() == 8) {
+ int no_items;
+ no_items = sscanf(begin.c_str(), %4i%2i%2i, year, month, day);
+ if (no_items != 3)
+   return Xapian::BAD_VALUENO;
+   } else if (begin.size() == 6) {
+ int no_items;
+ day = 1;
+ no_items = sscanf(begin.c_str(), %4i%2i, year, month);
+ if (no_items != 2)
+   return Xapian::BAD_VALUENO;
+   } else if (begin.size() == 4) {
+ int no_items;
+ day = 1;
+ month = 1;
+ no_items = sscanf(begin.c_str(), %4i, year);
+ if (no_items != 1)
+   return Xapian::BAD_VALUENO;
+   } else {
+ // no expected time format
+ return Xapian::BAD_VALUENO;
+   }
+
+   begintime = time(NULL);
+   timeinfo = localtime( begintime );
+   timeinfo - tm_year = year - 1900;
+   timeinfo - tm_mon = month - 1;
+   fprintf (stderr, Startdate %d %d %d\n,year,month,day);
+   timeinfo - tm_mday = day;
+   begintime = mktime ( timeinfo );
+
+   if (begintime == -1)
+ // no valid time format
+ return Xapian::BAD_VALUENO;
+
+   if (end.size() == 8) {
+ int no_items;
+ no_items = sscanf(end.c_str(), %4i%2i%2i, year, month, day);
+ if (no_items != 3)
+   return Xapian::BAD_VALUENO;
+   } else if (end.size() == 6) {
+ int no_items;
+ day = 31;
+ no_items = sscanf(end.c_str(), %4i%2i, year, month);
+ if (no_items != 2)
+   return Xapian::BAD_VALUENO;
+   } else if (end.size() == 4) {
+ int no_items;
+ day = 31;
+ month = 12;
+ no_items = sscanf(end.c_str(), %4i, year);
+ if (no_items != 1)
+   return Xapian::BAD_VALUENO;
+   } else {
+ // no expected time format
+ return Xapian::BAD_VALUENO;
+   }
+
+   timeinfo = localtime( begintime );
+   timeinfo - tm_year = year - 1900;
+   timeinfo - tm_mon = month - 1;
+   fprintf (stderr, Enddate %d %d %d\n,year,month,day);
+   timeinfo - tm_mday = day;
+   endtime = mktime ( timeinfo );
+   //XXX: plus 1 day to make the last day inclusive??
+
+   if (endtime == -1)
+ // no valid time format
+ return Xapian::BAD_VALUENO;
+   
+   begin.assign(Xapian::sortable_serialise(begintime));
+   end.assign(Xapian::sortable_serialise(endtime));
+
+return NOTMUCH_VALUE_TIMESTAMP;
+}
+};
+
 notmuch_database_t *
 notmuch_database_open (const char *path,
   notmuch_database_mode_t mode)
@@ -570,7 +661,8 @@ notmuch_database_open (const char *path,
notmuch-query_parser = new Xapian::QueryParser;
notmuch-term_gen = new Xapian::TermGenerator;
notmuch-term_gen-set_stemmer (Xapian::Stem (english));
-   notmuch-value_range_processor = new Xapian::NumberValueRangeProcessor 
(NOTMUCH_VALUE_TIMESTAMP, date:, true);
+   notmuch-value_range_processor = new MaildateValueRangeProcessor();
+ // (NOTMUCH_VALUE_TIMESTAMP);
 
notmuch-query_parser-set_default_op (Xapian::Query::OP_AND);
notmuch-query_parser-set_database (*notmuch-xapian_db);
-- 
1.6.3.3

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


Re: [notmuch] [PATCH] Make the date parser nicer

2010-01-22 Thread Sebastian Spaeth

Please find in the previous mail attached my patch (against my current
all-feature branch, but should pretty much apply to current master too).
It is a proof-of-concept to make the date parser nicer. The following 
searches work with this code:

notmuch show...
... date:2001..2010 (from beginning of 2001 until end of 2010)
... date:20011201..200506 (from 1001-12-01 until 2005-06-31

The code will pretty surely need some cleaning up, as I can hardly code
C, not to speak of C++. But at least it works and it is not very
intrusive.

(Ps. now that I think of it, I always use day 31 as last day, which is
surely wrong, it also still accepts some obviously wrong dates like
20040231)

We could also think about using a xapian DateValueRangeParser to do
that, but that would require saving the timestamp as MMDD in the
database (which we probably do not want).

Feedback welcome,
Sebastian
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [notmuch] Git feature branch

2010-01-22 Thread Carl Worth
On Fri, 22 Jan 2010 09:50:51 +0100, Sebastian Spaeth sebast...@sspaeth.de 
wrote:
 My feature-branch is still located here:
 http://github.com/spaetz/notmuch-all-feature
 
 So far things work fine for me. It would be cool if Carl would merge
 (parts of?) it.

Very much appreciated!

Thanks for putting this together and publishing it.

And I do apologize that my branch has been so stagnant lately. We've
just completed a fabulous linux.conf.au. This included lots of hallway
discussion of Notmuch, a Notmuch BOF, and a Notmuch lightning talk, but
not much of a chance to sit and review/merge the backlog of patches.

Oh, but we did succeed at getting a notmuch Debian package uploaded,
(and there's now a debian branch in my repository which I pulled from
the master branch of the shared notmuch repository on alioth).

Anyway, I'll be on vacation for the next few days, so will likely not
have much, (likely have not much?), time for patch merging.

But I *am* anxious to get back to the backlog. And in the meantime, I
really appreciate others merging and sharing patches.

-Carl


pgpgkv5A2UQx5.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [notmuch] indexing mail?

2010-01-22 Thread Jesse Rosenthal
On Sat, 23 Jan 2010 19:09:35 +1300, Carl Worth cwo...@cworth.org wrote:
 But I've since pushed a separate patch to fix this bug. Please give it a
 try and let me know what you think.

I just gave it a try, and building failed because of a seeming
misspelling on line 285 (`DT_UKNOWN'), from commit
344c48a47de23cc63f1885d850b82359d1a34064 . Fixing the misspelling fixed
the build.

Thanks, as always, for all your work on this.

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