[notmuch] [PATCH (rebased)] Handle message renames in mail spool

2009-12-02 Thread Mikhail Gusarov
In order to handle message renames the following changes were deemed necessary:

* Mtime check on individual files was disabled. As files may be moved around
without changing their mtime, it's necessary to parse them even if they appear
old in case old message was moved. mtime check on directories was kept as moving
files changes mtime of directory.

* If message being parsed is already found in database under different path,
then this message is considered to be moved, path is updated in database and
this file does not undergo further processing.

Note that after applying this patch notmuch still does not handle copying files
(which is harmless, database will point to the last copy of message found during
'notmuch new') and deleting files (which is more serious, as dangling entries
will show up in searches).

Signed-off-by: Mikhail Gusarov dotted...@dottedmag.net
---
 lib/database.cc |   32 ++-
 notmuch-new.c   |  116 ++
 2 files changed, 78 insertions(+), 70 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 23ddd4a..45d8fc7 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -993,19 +993,31 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
_notmuch_message_set_filename (message, filename);
_notmuch_message_add_term (message, type, mail);
-   } else {
-   ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
-   goto DONE;
-   }
 
-   ret = _notmuch_database_link_message (notmuch, message, message_file);
-   if (ret)
-   goto DONE;
+   ret = _notmuch_database_link_message (notmuch, message, 
message_file);
+   if (ret)
+   goto DONE;
 
-   date = notmuch_message_file_get_header (message_file, date);
-   _notmuch_message_set_date (message, date);
+   date = notmuch_message_file_get_header (message_file, date);
+   _notmuch_message_set_date (message, date);
 
-   _notmuch_message_index_file (message, filename);
+   _notmuch_message_index_file (message, filename);
+   } else {
+   const char *old_filename = notmuch_message_get_filename (message);
+   if (strcmp (old_filename, filename) == 0) {
+   /* We have already seen it */
+   goto DONE;
+   } else {
+   if (access (old_filename, R_OK) == 0) {
+   /* old_filename still exists, we've got a duplicate */
+   ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
+   goto DONE;
+   } else {
+   /* Message file has been moved/renamed */
+   _notmuch_message_set_filename (message, filename);
+   }
+   }
+   }
 
_notmuch_message_sync (message);
 } catch (const Xapian::Error error) {
diff --git a/notmuch-new.c b/notmuch-new.c
index 9d20616..d595fc4 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -217,66 +217,62 @@ add_files_recursive (notmuch_database_t *notmuch,
}
 
if (S_ISREG (st-st_mode)) {
-   /* If the file hasn't been modified since the last
-* add_files, then we need not look at it. */
-   if (path_dbtime == 0 || st-st_mtime  path_dbtime) {
-   state-processed_files++;
-
-   if (state-verbose) {
-   if (state-output_is_a_tty)
-   printf(\r\033[K);
-
-   printf (%i/%i: %s,
-   state-processed_files,
-   state-total_files,
-   next);
-
-   putchar((state-output_is_a_tty) ? '\r' : '\n');
-   fflush (stdout);
-   }
-
-   status = notmuch_database_add_message (notmuch, next, message);
-   switch (status) {
-   /* success */
-   case NOTMUCH_STATUS_SUCCESS:
-   state-added_messages++;
-   tag_inbox_and_unread (message);
-   break;
-   /* Non-fatal issues (go on to next file) */
-   case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
-   /* Stay silent on this one. */
-   break;
-   case NOTMUCH_STATUS_FILE_NOT_EMAIL:
-   fprintf (stderr, Note: Ignoring non-mail file: %s\n,
-next);
-   break;
-   /* Fatal issues. Don't process anymore. */
-   case NOTMUCH_STATUS_READONLY_DATABASE:
-   case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
-   case NOTMUCH_STATUS_OUT_OF_MEMORY:
-   fprintf (stderr, Error: %s. Halting processing.\n,
-notmuch_status_to_string (status));
-   ret = status

Re: [notmuch] [PATCH (rebased)] Handle message renames in mail spool

2009-12-04 Thread Mikhail Gusarov

Twas brillig at 10:05:05 04.12.2009 UTC-08 when cwo...@cworth.org did gyre and 
gimble:

 CW Plus, notmuch already handles duplicate mail just fine, (in that the
 CW user only sees one copy at least). And I tag my mail differently when
 CW one of my addresses appears on the CC list, so I definitely prefer that
 CW people CC me when they want to call my specific attention to a message.

The only problem with Cc is that Mailman suppresses duplicate messages and hence
there is no List-Id: on message.

-- 
  http://fossarchy.blogspot.com/


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


Re: [notmuch] [PATCH (rebased)] Handle message renames in mail spool

2009-12-04 Thread Mikhail Gusarov

Twas brillig at 16:39:50 04.12.2009 UTC-08 when cwo...@cworth.org did gyre and 
gimble:

 CW But when viewing an actual message, I'm still planning on having
 CW notmuch just return an arbitrary filename from the list of
 CW filenames associated with that message. Does anyone see any problem
 CW with that? Can you think of a case where you'd really care about
 CW seeing one or the other of a particular duplicated message?

There might be different Reply-To fields.

So I'd just return bigger dup, as it probably contains more information
:)

-- 
  http://fossarchy.blogspot.com/


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


Re: Use of strcasestr

2010-04-12 Thread Mikhail Gusarov

Twas brillig at 15:58:10 12.04.2010 UTC+02 when t...@dbservice.com did gyre and 
gimble:

 TC In 4fd9ea0 (guess From address from Received headers, 2010-04-06) you 
introduced
 TC strcasestr, which is not portable, see 82e47ec (notmuch reply: Use strstr
 TC instead of strcasestr for portability., 2010-02-04).

 TC Is strcasestr really necessary there or can it be replaced with strstr?

strcasecmp is POSIX.1-2001.

If you know any OS which does not have it, add a new file to compat/ subdir.

-- 
  http://fossarchy.blogspot.com/


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


[notmuch] [PATCH 2/2] Include to get uint32_t in C++ file with gcc 4.4

2009-11-17 Thread Mikhail Gusarov

Signed-off-by: Mikhail Gusarov 
---
 lib/message.cc |2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index 72c350f..a4b090b 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -21,6 +21,8 @@
 #include "notmuch-private.h"
 #include "database-private.h"

+#include 
+
 #include 

 #include 
-- 
1.6.3.3



[notmuch] Working with Maildir storage?

2009-11-18 Thread Mikhail Gusarov

Twas brillig at 14:00:54 17.11.2009 UTC-05 when lars at seas.harvard.edu did 
gyre and gimble:

 LK> Resulted in 4604 lines of errors along the lines of:

 LK>   Error opening
 LK>   
/home/lars/Mail/read-messages.2008/cur/1246413773.24928_27334.hostname,U=3026:2,S:
 LK>   Too many open files

See the patch just posted here.

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] Working with Maildir storage?

2009-11-18 Thread Mikhail Gusarov

Twas brillig at 15:33:01 17.11.2009 UTC-05 when lars at seas.harvard.edu did 
gyre and gimble:

 LK> Is the list archived anywhere?  The obvious archives
 LK> (http://notmuchmail.org/pipermail/notmuch/) aren't available, and I
 LK> think I subscribed too late to get the patch (I only just saw the
 LK> discussion about it).

 LK> It doesn't look like the patch is in git yet.

Just has been pushed

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] [PATCH] Handle rename of message file

2009-11-18 Thread Mikhail Gusarov
If message file has been renamed, just update filename in the DB.

Signed-off-by: Mikhail Gusarov 
---
 lib/database.cc |   21 -
 1 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 3c8d626..c4eb8b6 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -925,20 +925,23 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
_notmuch_message_set_filename (message, filename);
_notmuch_message_add_term (message, "type", "mail");
+
+   ret = _notmuch_database_link_message (notmuch, message, 
message_file);
+   if (ret)
+   goto DONE;
+
+   date = notmuch_message_file_get_header (message_file, "date");
+   _notmuch_message_set_date (message, date);
+
+   _notmuch_message_index_file (message, filename);
+   } else if (strcmp(notmuch_message_get_filename(message), filename)) {
+   /* Message file has been moved/renamed */
+   _notmuch_message_set_filename (message, filename);
} else {
ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
goto DONE;
}

-   ret = _notmuch_database_link_message (notmuch, message, message_file);
-   if (ret)
-   goto DONE;
-
-   date = notmuch_message_file_get_header (message_file, "date");
-   _notmuch_message_set_date (message, date);
-
-   _notmuch_message_index_file (message, filename);
-
_notmuch_message_sync (message);
 } catch (const Xapian::Error ) {
fprintf (stderr, "A Xapian exception occurred: %s.\n",
-- 
1.6.3.3



[notmuch] [PATCH] Handle rename of message file

2009-11-19 Thread Mikhail Gusarov

Twas brillig at 02:08:15 19.11.2009 UTC+01 when cworth at cworth.org did gyre 
and gimble:

 CW> I believe you said in IRC that this patch is not ready yet.

Yes.

 CW> I'd love to hear more from you on any experiments/ideas you have in
 CW> this area. It would be a really nice feature to have, (particularly
 CW> for people who are experimenting with notmuch while still using
 CW> some other primary email program that keeps fiddling with the
 CW> filenames).

Did not have time to work on it further yet.

The only dumb idea I have in mind is hardlinking all mail to separate
directory in order to make a "pristine copy" which does not change as
time goes. This directory could be cleaned up: if some file has only 1
link, then it was deleted from main mail spool and should be deleted


[notmuch] [PATCH] Handle rename of message file

2009-11-19 Thread Mikhail Gusarov

Twas brillig at 18:06:09 18.11.2009 UTC-08 when keithp at keithp.com did gyre 
and gimble:

 KP> Checking for new files is easy; notmuch already does that, and so
 KP> handling renames doesn't seem all that difficult.

Except rename does not change mtime of file, and so it won't be picked
up by 'notmuch new'.

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] [PATCH] Allow to redefine notmuch binary name and path in elisp mode

2009-11-20 Thread Mikhail Gusarov

Signed-off-by: Mikhail Gusarov 
---
 notmuch.el |   13 -
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 1fc54c3..f97950f 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -71,6 +71,9 @@ pattern can still test against the entire line).")
 (defvar notmuch-show-signature-lines-max 12
   "Maximum length of signature that will be hidden by default.")

+(defvar notmuch-command "notmuch"
+  "Notmuch binary location")
+
 (set 'notmuch-show-message-begin-regexp"message{")
 (set 'notmuch-show-message-end-regexp  "message}")
 (set 'notmuch-show-header-begin-regexp "header{")
@@ -251,7 +254,7 @@ buffer."

 (defun notmuch-reply (query-string)
   (switch-to-buffer (generate-new-buffer "notmuch-draft"))
-  (call-process "notmuch" nil t nil "reply" query-string)
+  (call-process notmuch-command nil t nil "reply" query-string)
   (goto-char (point-min))
   (if (re-search-forward "^$" nil t)
   (progn
@@ -690,7 +693,7 @@ thread from that buffer can be show when done with this 
one)."
   (erase-buffer)
   (goto-char (point-min))
   (save-excursion
-   (call-process "notmuch" nil t nil "show" thread-id)
+   (call-process notmuch-command nil t nil "show" thread-id)
(notmuch-show-markup-messages)
)
   (run-hooks 'notmuch-show-hook)
@@ -851,7 +854,7 @@ and will also appear in a buffer named \"*Notmuch 
errors*\"."
   (let ((error-buffer (get-buffer-create "*Notmuch errors*")))
 (with-current-buffer error-buffer
(erase-buffer))
-(if (eq (apply 'call-process "notmuch" nil error-buffer nil args) 0)
+(if (eq (apply 'call-process notmuch-command nil error-buffer nil args) 0)
(point)
   (progn
(with-current-buffer error-buffer
@@ -917,8 +920,8 @@ This function advances point to the next line when 
finished."
   (goto-char (point-min))
   (save-excursion
(if oldest-first
-   (call-process "notmuch" nil t nil "search" "--sort=oldest-first" 
query)
- (call-process "notmuch" nil t nil "search" "--sort=newest-first" 
query))
+   (call-process notmuch-command nil t nil "search" 
"--sort=oldest-first" query)
+ (call-process notmuch-command nil t nil "search" 
"--sort=newest-first" query))
(notmuch-search-markup-thread-ids)
))
 (run-hooks 'notmuch-search-hook)))
-- 
1.6.3.3



[notmuch] [PATCH] Add notmuch.1.gz to files to be cleaned

2009-11-20 Thread Mikhail Gusarov

Signed-off-by: Mikhail Gusarov 
---
 Makefile.local |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/Makefile.local b/Makefile.local
index ecd4ceb..bf81c03 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -45,4 +45,4 @@ install-emacs: install emacs
install -m0644 notmuch.elc $(DESTDIR)$(emacs_lispdir)

 SRCS  := $(SRCS) $(notmuch_client_srcs)
-CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc
+CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc notmuch.1.gz
-- 
1.6.3.3



[notmuch] [PATCH] RFC: quiet make

2009-11-20 Thread Mikhail Gusarov
I don't entirely like duplicating every command line in makefile,
so this patch is RFC. Someone with bigger Make-fu than mine probably
knows a better way.

Signed-off-by: Mikhail Gusarov 
---
 Makefile   |   36 
 Makefile.local |   10 ++
 lib/Makefile.local |5 +
 3 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile
index b6861e9..72a72ae 100644
--- a/Makefile
+++ b/Makefile
@@ -32,29 +32,65 @@ include lib/Makefile.local
 include Makefile.config

 %.o: %.cc $(all_deps)
+ifeq ($(V),1)
$(CXX) -c $(CFLAGS) $(CXXFLAGS) $< -o $@
+else
+   @echo CXX $<
+   @$(CXX) -c $(CFLAGS) $(CXXFLAGS) $< -o $@
+endif

 %.o: %.c $(all_deps)
+ifeq ($(V),1)
$(CC) -c $(CFLAGS) $< -o $@
+else
+   @echo CC $<
+   @$(CC) -c $(CFLAGS) $< -o $@
+endif

 %.elc: %.el
+ifeq ($(V),1)
emacs -batch -f batch-byte-compile $<
+else
+   @echo ELCOMPILE $<
+   @emacs -batch -f batch-byte-compile $<
+endif

 .deps/%.d: %.c $(all_deps)
+ifeq ($(V),1)
+   set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
+   $(CC) -M $(CPPFLAGS) $(CFLAGS) $< > $@.; \
+   sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@. > $@; \
+   rm -f $@.
+else
+   @echo DEPCXX $<
@set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
$(CC) -M $(CPPFLAGS) $(CFLAGS) $< > $@.; \
sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@. > $@; \
rm -f $@.
+endif

 .deps/%.d: %.cc $(all_deps)
+ifeq ($(V),1)
+   set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
+   $(CXX) -M $(CPPFLAGS) $(CXXFLAGS) $< > $@.; \
+   sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@. > $@; \
+   rm -f $@.
+else
+   @echo DEPCC $<
@set -e; rm -f $@; mkdir -p $$(dirname $@) ; \
$(CXX) -M $(CPPFLAGS) $(CXXFLAGS) $< > $@.; \
sed 's,'$$(basename $*)'\.o[ :]*,$*.o $@ : ,g' < $@. > $@; \
rm -f $@.
+endif

 DEPS := $(SRCS:%.c=.deps/%.d)
 DEPS := $(DEPS:%.cc=.deps/%.d)
 -include $(DEPS)

 clean:
+ifeq ($(V),1)
rm -f $(CLEAN); rm -rf .deps
+else
+   @echo CLEAN
+   @rm -f $(CLEAN); rm -rf .deps
+endif
diff --git a/Makefile.local b/Makefile.local
index bf81c03..0addfed 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -20,10 +20,20 @@ notmuch_client_srcs =   \

 notmuch_client_modules = $(notmuch_client_srcs:.c=.o)
 notmuch: $(notmuch_client_modules) lib/notmuch.a
+ifeq ($(V),1)
$(CXX) $^ $(LDFLAGS) -o $@
+else
+   @echo LINK $^
+   @$(CXX) $^ $(LDFLAGS) -o $@
+endif

 notmuch.1.gz: notmuch.1
+ifeq ($(V),1)
gzip --stdout notmuch.1 > notmuch.1.gz
+else
+   @echo GZIP $<
+   @gzip --stdout notmuch.1 > notmuch.1.gz
+endif

 install: all notmuch.1.gz
for d in $(DESTDIR)$(prefix)/bin/ $(DESTDIR)$(prefix)/share/man/man1 \
diff --git a/lib/Makefile.local b/lib/Makefile.local
index 79f7b0b..5a66716 100644
--- a/lib/Makefile.local
+++ b/lib/Makefile.local
@@ -18,7 +18,12 @@ libnotmuch_cxx_srcs =\

 libnotmuch_modules = $(libnotmuch_c_srcs:.c=.o) $(libnotmuch_cxx_srcs:.cc=.o)
 $(dir)/notmuch.a: $(libnotmuch_modules)
+ifeq ($(V),1)
$(AR) rcs $@ $^
+else
+   @echo AR $^
+   @$(AR) rcs $@ $^
+endif

 SRCS  := $(SRCS) $(libnotmuch_c_srcs) $(libnotmuch_cxx_srcs)
 CLEAN := $(CLEAN) $(libnotmuch_modules) $(dir)/notmuch.a
-- 
1.6.3.3



[notmuch] [PATCH] RFC: quiet make

2009-11-21 Thread Mikhail Gusarov

Twas brillig at 14:16:52 21.11.2009 UTC+01 when cworth at cworth.org did gyre 
and gimble:

 CW> Meanwhile, the feature I've always wanted with systems like this is
 CW> to document to the user that there's the possibility of adding a
 CW> "V=1" to the command line to get the full output.

I have had another idea in mind which might be useful: a "header" for
silent make mode which explains what commands are run exactly, including
placeholders like $@ $^, so it is not necessary to run with make V=1 to
figure out what's going on.

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] [PATCH] Makefile: Magic silent rules.

2009-11-22 Thread Mikhail Gusarov

Twas brillig at 19:02:22 21.11.2009 UTC+00 when chris at chris-wilson.co.uk did 
gyre and gimble:

 CW> Use the facilities of GNU make to create a magic function that will
 CW> on the first invocation print a description of how to enable
 CW> verbose compile lines and then print the quiet rule.

Ugh. With silent rules enabled it gives me

/bin/sh: --rsyncable: not found

at the end (apparently gzip was eaten out)

And with V=1 it strips first two symbols from the command name:

c -Wall -Wextra -Wmissing-declarations -Wwrite-strings -Wswitch-enum 
-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/glib-2.0 
-I/usr/lib/glib-2.0/include -I/usr/include/gmime-2.4   -Ilib  lib/query.cc -o 
lib/query.o
make: c: Command not found
make: [lib/query.o] Error 127 (ignored)
c -Wall -Wextra -Wmissing-declarations -Wwrite-strings -Wswitch-enum 
-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/glib-2.0 
-I/usr/lib/glib-2.0/include -I/usr/include/gmime-2.4   -Ilib  lib/thread.cc -o 
lib/thread.o
make: c: Command not found
make: [lib/thread.o] Error 127 (ignored)
rcs lib/notmuch.a lib/libsha1.o lib/message-file.o lib/messages.o lib/sha1.o 
lib/tags.o lib/xutil.o lib/database.o lib/index.o lib/message.o lib/query.o 
lib/thread.o
make: rcs: Command not found


-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] [PATCH] Makefile: Magic silent rules.

2009-11-22 Thread Mikhail Gusarov

Twas brillig at 20:32:20 21.11.2009 UTC+00 when chris at chris-wilson.co.uk did 
gyre and gimble:

 CW> Use the facilities of GNU make to create a magic function that will
 CW> on the first invocation print a description of how to enable
 CW> verbose compile lines and then print the quiet rule.

Uhm. Now it eats much less :)

$ make
...
  GZIP  notmuch.1.gz
/bin/sh: --rsyncable: not found
make: *** [notmuch.1.gz] Error 127
$

$ make V=1
...
rsyncable --stdout notmuch.1 > notmuch.1.gz
/bin/sh: rsyncable: not found
make: [notmuch.1.gz] Error 127 (ignored)
$

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] [PATCH] Handle message renames in mail spool

2009-11-23 Thread Mikhail Gusarov
In order to handle message renames the following changes were deemed necessary:

* Mtime check on individual files was disabled. As files may be moved around
without changing their mtime, it's necessary to parse them even if they appear
old in case old message was moved. mtime check on directories was kept as moving
files changes mtime of directory.

* If message being parsed is already found in database under different path,
then this message is considered to be moved, path is updated in database and
this file does not undergo further processing.

Note that after applying this patch notmuch still does not handle copying files
(which is harmless, database will point to the last copy of message found during
'notmuch new') and deleting files (which is more serious, as dangling entries
will show up in searches).

Signed-off-by: Mikhail Gusarov 
---
 lib/database.cc |   21 +++-
 notmuch-new.c   |   92 ++
 2 files changed, 56 insertions(+), 57 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 2c90019..d88efbe 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -990,20 +990,23 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
_notmuch_message_set_filename (message, filename);
_notmuch_message_add_term (message, "type", "mail");
+
+   ret = _notmuch_database_link_message (notmuch, message, 
message_file);
+   if (ret)
+   goto DONE;
+
+   date = notmuch_message_file_get_header (message_file, "date");
+   _notmuch_message_set_date (message, date);
+
+   _notmuch_message_index_file (message, filename);
+   } else if (strcmp(notmuch_message_get_filename(message), filename)) {
+   /* Message file has been moved/renamed */
+   _notmuch_message_set_filename (message, filename);
} else {
ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
goto DONE;
}

-   ret = _notmuch_database_link_message (notmuch, message, message_file);
-   if (ret)
-   goto DONE;
-
-   date = notmuch_message_file_get_header (message_file, "date");
-   _notmuch_message_set_date (message, date);
-
-   _notmuch_message_index_file (message, filename);
-
_notmuch_message_sync (message);
 } catch (const Xapian::Error ) {
fprintf (stderr, "A Xapian exception occurred adding message: %s.\n",
diff --git a/notmuch-new.c b/notmuch-new.c
index 0dd2784..d16679c 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -174,54 +174,50 @@ add_files_recursive (notmuch_database_t *notmuch,
}

if (S_ISREG (st->st_mode)) {
-   /* If the file hasn't been modified since the last
-* add_files, then we need not look at it. */
-   if (path_dbtime == 0 || st->st_mtime > path_dbtime) {
-   state->processed_files++;
-
-   status = notmuch_database_add_message (notmuch, next, );
-   switch (status) {
-   /* success */
-   case NOTMUCH_STATUS_SUCCESS:
-   state->added_messages++;
-   tag_inbox_and_unread (message);
-   break;
-   /* Non-fatal issues (go on to next file) */
-   case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
-   /* Stay silent on this one. */
-   break;
-   case NOTMUCH_STATUS_FILE_NOT_EMAIL:
-   fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
-next);
-   break;
-   /* Fatal issues. Don't process anymore. */
-   case NOTMUCH_STATUS_READONLY_DATABASE:
-   case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
-   case NOTMUCH_STATUS_OUT_OF_MEMORY:
-   fprintf (stderr, "Error: %s. Halting processing.\n",
-notmuch_status_to_string (status));
-   ret = status;
-   goto DONE;
-   default:
-   case NOTMUCH_STATUS_FILE_ERROR:
-   case NOTMUCH_STATUS_NULL_POINTER:
-   case NOTMUCH_STATUS_TAG_TOO_LONG:
-   case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
-   case NOTMUCH_STATUS_LAST_STATUS:
-   INTERNAL_ERROR ("add_message returned unexpected value: 
%d",  status);
-   goto DONE;
-   }
-
-   if (message) {
-   notmuch_message_destroy (message);
-   message = NULL;
-   }
-
-   if (do_add_files_print_progress) {
-   do_add_files_print_progress = 0;
-

[notmuch] Notmuch doesn't index new mails when mail location contains symlinks

2009-11-23 Thread Mikhail Gusarov

Twas brillig at 14:55:40 23.11.2009 UTC+01 when tassilo at member.fsf.org did 
gyre and gimble:

 TH> Whenever I delete those symlinks and created them anew, the new
 TH> mails get indexed with the next "notmuch new".  Of course, I could
 TH> create a script that does exactly that, but there should be a
 TH> better way, right?

Probably mail does not get indexed due to mtime checks. Please try
whether touch'ing directory with mailboxes makes it work.

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] Notmuch doesn't index new mails when mail location contains symlinks

2009-11-23 Thread Mikhail Gusarov

Twas brillig at 16:01:41 23.11.2009 UTC+01 when tassilo at member.fsf.org did 
gyre and gimble:

 >>> Probably mail does not get indexed due to mtime checks. Please try
 >>> whether touch'ing directory with mailboxes makes it work.
 >> No, it seems that doesn't help either.
 TH> Ah, I'm stupid!  I don't have to touch the symlinks or the
 TH> directories inside the locations the symlinks point to, but instead
 TH> I have to touch the top-level directory where the symlinks are
 TH> contained in.  Then it works as expected, AFAICT.

Really odd.

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] Notmuch doesn't index new mails when mail location contains symlinks

2009-11-23 Thread Mikhail Gusarov

Twas brillig at 16:03:00 23.11.2009 UTC+01 when jed at 59A2.org did gyre and 
gimble:

 JB> The real solution is for notmuch to check mtime of whatever the
 JB> symlink's target.

It does exactly this AFACT, stat() everywhere, not lstat().

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] [PATCH] Handle message renames in mail spool

2009-11-26 Thread Mikhail Gusarov

Twas brillig at 07:40:15 26.11.2009 UTC-08 when cworth at cworth.org did gyre 
and gimble:

 CW> I *really* want this patch in, since I think a lot of current users
 CW> would really benefit from it. I only see one big problem with it:

Did you test the performance hit caused by disabling mtime checks?

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] [PATCH] Handle message renames in mail spool

2009-11-27 Thread Mikhail Gusarov
In order to handle message renames the following changes were deemed necessary:

* Mtime check on individual files was disabled. As files may be moved around
without changing their mtime, it's necessary to parse them even if they appear
old in case old message was moved. mtime check on directories was kept as moving
files changes mtime of directory.

* If message being parsed is already found in database under different path,
then this message is considered to be moved, path is updated in database and
this file does not undergo further processing.

Note that after applying this patch notmuch still does not handle copying files
(which is harmless, database will point to the last copy of message found during
'notmuch new') and deleting files (which is more serious, as dangling entries
will show up in searches).

Signed-off-by: Mikhail Gusarov 
---
 lib/database.cc |   32 +--
 notmuch-new.c   |   92 ++
 2 files changed, 66 insertions(+), 58 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 2c90019..257c0b8 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -990,19 +990,31 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
_notmuch_message_set_filename (message, filename);
_notmuch_message_add_term (message, "type", "mail");
-   } else {
-   ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
-   goto DONE;
-   }

-   ret = _notmuch_database_link_message (notmuch, message, message_file);
-   if (ret)
-   goto DONE;
+   ret = _notmuch_database_link_message (notmuch, message, 
message_file);
+   if (ret)
+   goto DONE;

-   date = notmuch_message_file_get_header (message_file, "date");
-   _notmuch_message_set_date (message, date);
+   date = notmuch_message_file_get_header (message_file, "date");
+   _notmuch_message_set_date (message, date);

-   _notmuch_message_index_file (message, filename);
+   _notmuch_message_index_file (message, filename);
+   } else {
+   const char *old_filename = notmuch_message_get_filename (message);
+   if (strcmp (old_filename, filename) == 0) {
+   /* We have already seen it */
+   goto DONE;
+   } else {
+   if (access (old_filename, R_OK) == 0) {
+   /* old_filename still exists, we've got a duplicate */
+   ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
+   goto DONE;
+   } else {
+   /* Message file has been moved/renamed */
+   _notmuch_message_set_filename (message, filename);
+   }
+   }
+   }

_notmuch_message_sync (message);
 } catch (const Xapian::Error ) {
diff --git a/notmuch-new.c b/notmuch-new.c
index 0dd2784..d16679c 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -174,54 +174,50 @@ add_files_recursive (notmuch_database_t *notmuch,
}

if (S_ISREG (st->st_mode)) {
-   /* If the file hasn't been modified since the last
-* add_files, then we need not look at it. */
-   if (path_dbtime == 0 || st->st_mtime > path_dbtime) {
-   state->processed_files++;
-
-   status = notmuch_database_add_message (notmuch, next, );
-   switch (status) {
-   /* success */
-   case NOTMUCH_STATUS_SUCCESS:
-   state->added_messages++;
-   tag_inbox_and_unread (message);
-   break;
-   /* Non-fatal issues (go on to next file) */
-   case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
-   /* Stay silent on this one. */
-   break;
-   case NOTMUCH_STATUS_FILE_NOT_EMAIL:
-   fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
-next);
-   break;
-   /* Fatal issues. Don't process anymore. */
-   case NOTMUCH_STATUS_READONLY_DATABASE:
-   case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
-   case NOTMUCH_STATUS_OUT_OF_MEMORY:
-   fprintf (stderr, "Error: %s. Halting processing.\n",
-notmuch_status_to_string (status));
-   ret = status;
-   goto DONE;
-   default:
-   case NOTMUCH_STATUS_FILE_ERROR:
-   case NOTMUCH_STATUS_NULL_POINTER:
-   case NOTMUCH_STATUS_TAG_TOO_LONG:
-   case NOTMUCH_STATUS_UNBALANCED_FREEZE_THAW:
-   case NOTMUCH_STATUS_LAST_STATUS:
- 

[notmuch] Using notmuch from Ruby, Python, et al.

2009-11-28 Thread Mikhail Gusarov

Twas brillig at 18:55:28 27.11.2009 UTC-08 when cworth at cworth.org did gyre 
and gimble:

 >> Q: Why are my replies five sentences or less?
 >> A: http://five.sentenc.es/

 CW> There---just five this time. :-)

I imagine hook that counts the number of sentences and inserts proper
signature :)

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] [PATCH] Use libgcrypt for hashing.

2009-11-28 Thread Mikhail Gusarov

Twas brillig at 21:28:03 27.11.2009 UTC-06 when jeff at ocjtech.us did gyre and 
gimble:

 JCO> Instead of including a private implementation of the SHA1 hash

xserver went this road, and now it has
--with-sha1=libc|libmd|libgcrypt|libcrypto|libsha1|CommonCrypto in
configure.

 JCO> This means less code of our own to maintain and

As libsha1 maintainer I'm volunteering to maintain in-tree copy in
notmuch :)

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] [PATCH 2/3] add checking for zlib development libraries to configure script

2009-11-29 Thread Mikhail Gusarov

Twas brillig at 18:57:36 28.11.2009 UTC-05 when jrollins at finestructure.net 
did gyre and gimble:

 JGR> + sudo apt-get install libxapian-dev libgmime-2.4-dev
 JGR> libtalloc-dev libz-dev

Proper fix is to fix libgmime-2.4.pc upstream to stop exposing -lz

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] [PATCH (rebased)] Handle message renames in mail spool

2009-12-03 Thread Mikhail Gusarov
In order to handle message renames the following changes were deemed necessary:

* Mtime check on individual files was disabled. As files may be moved around
without changing their mtime, it's necessary to parse them even if they appear
old in case old message was moved. mtime check on directories was kept as moving
files changes mtime of directory.

* If message being parsed is already found in database under different path,
then this message is considered to be moved, path is updated in database and
this file does not undergo further processing.

Note that after applying this patch notmuch still does not handle copying files
(which is harmless, database will point to the last copy of message found during
'notmuch new') and deleting files (which is more serious, as dangling entries
will show up in searches).

Signed-off-by: Mikhail Gusarov 
---
 lib/database.cc |   32 ++-
 notmuch-new.c   |  116 ++
 2 files changed, 78 insertions(+), 70 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 23ddd4a..45d8fc7 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -993,19 +993,31 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
if (private_status == NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
_notmuch_message_set_filename (message, filename);
_notmuch_message_add_term (message, "type", "mail");
-   } else {
-   ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
-   goto DONE;
-   }

-   ret = _notmuch_database_link_message (notmuch, message, message_file);
-   if (ret)
-   goto DONE;
+   ret = _notmuch_database_link_message (notmuch, message, 
message_file);
+   if (ret)
+   goto DONE;

-   date = notmuch_message_file_get_header (message_file, "date");
-   _notmuch_message_set_date (message, date);
+   date = notmuch_message_file_get_header (message_file, "date");
+   _notmuch_message_set_date (message, date);

-   _notmuch_message_index_file (message, filename);
+   _notmuch_message_index_file (message, filename);
+   } else {
+   const char *old_filename = notmuch_message_get_filename (message);
+   if (strcmp (old_filename, filename) == 0) {
+   /* We have already seen it */
+   goto DONE;
+   } else {
+   if (access (old_filename, R_OK) == 0) {
+   /* old_filename still exists, we've got a duplicate */
+   ret = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID;
+   goto DONE;
+   } else {
+   /* Message file has been moved/renamed */
+   _notmuch_message_set_filename (message, filename);
+   }
+   }
+   }

_notmuch_message_sync (message);
 } catch (const Xapian::Error ) {
diff --git a/notmuch-new.c b/notmuch-new.c
index 9d20616..d595fc4 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -217,66 +217,62 @@ add_files_recursive (notmuch_database_t *notmuch,
}

if (S_ISREG (st->st_mode)) {
-   /* If the file hasn't been modified since the last
-* add_files, then we need not look at it. */
-   if (path_dbtime == 0 || st->st_mtime > path_dbtime) {
-   state->processed_files++;
-
-   if (state->verbose) {
-   if (state->output_is_a_tty)
-   printf("\r\033[K");
-
-   printf ("%i/%i: %s",
-   state->processed_files,
-   state->total_files,
-   next);
-
-   putchar((state->output_is_a_tty) ? '\r' : '\n');
-   fflush (stdout);
-   }
-
-   status = notmuch_database_add_message (notmuch, next, );
-   switch (status) {
-   /* success */
-   case NOTMUCH_STATUS_SUCCESS:
-   state->added_messages++;
-   tag_inbox_and_unread (message);
-   break;
-   /* Non-fatal issues (go on to next file) */
-   case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
-   /* Stay silent on this one. */
-   break;
-   case NOTMUCH_STATUS_FILE_NOT_EMAIL:
-   fprintf (stderr, "Note: Ignoring non-mail file: %s\n",
-next);
-   break;
-   /* Fatal issues. Don't process anymore. */
-   case NOTMUCH_STATUS_READONLY_DATABASE:
-   case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
-   case NOTMUCH_STATUS_OUT_OF_MEMORY:
-   fprintf (stderr, "Error: %s. Halting processing.\n&qu

[notmuch] [PATCH (rebased)] Handle message renames in mail spool

2009-12-05 Thread Mikhail Gusarov

Twas brillig at 10:05:05 04.12.2009 UTC-08 when cworth at cworth.org did gyre 
and gimble:

 CW> Plus, notmuch already handles duplicate mail just fine, (in that the
 CW> user only sees one copy at least). And I tag my mail differently when
 CW> one of my addresses appears on the CC list, so I definitely prefer that
 CW> people CC me when they want to call my specific attention to a message.

The only problem with Cc is that Mailman suppresses duplicate messages and hence
there is no List-Id: on message.

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] [PATCH (rebased)] Handle message renames in mail spool

2009-12-05 Thread Mikhail Gusarov

Twas brillig at 10:35:27 04.12.2009 UTC-08 when cworth at cworth.org did gyre 
and gimble:

 >> The only problem with Cc is that Mailman suppresses duplicate
 >> messages and hence there is no List-Id: on message.

 CW> But the above sounds like the List-Id header is unreliable enough
 CW> to be useless.  Any reason not to just use something like
 CW> to:notmuch at notmuchmail to match messages sent to a list like this
 CW> one?

Automated processing. I'd go crazy to put all mailing lists' addresses
to .procmailrc instead of simple sorter in sed. But it seems it's the
only reliable way.

 CW> I think mailman defaults to not allowing messages with the
 CW> mailing-list address implicit (such as in a Bcc) so it seems like
 CW> matching the list recipient will be more reliable than hoping the
 CW> List-Id is always there.

Yep. Unfortunately.

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] [PATCH (rebased)] Handle message renames in mail spool

2009-12-05 Thread Mikhail Gusarov

Twas brillig at 16:39:50 04.12.2009 UTC-08 when cworth at cworth.org did gyre 
and gimble:

 CW> But when viewing an actual message, I'm still planning on having
 CW> notmuch just return an arbitrary filename from the list of
 CW> filenames associated with that message. Does anyone see any problem
 CW> with that? Can you think of a case where you'd really care about
 CW> seeing one or the other of a particular duplicated message?

There might be different Reply-To fields.

So I'd just return bigger dup, as it probably contains more information
:)

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] [PATCH (rebased)] Handle message renames in mail spool

2009-12-17 Thread Mikhail Gusarov

Twas brillig at 16:51:17 16.12.2009 UTC-07 when bdale at gag.com did gyre and 
gimble:

 >> But the above sounds like the List-Id header is unreliable enough to
 >> be useless.

 BG> FWIW, that does not match my experience.

Yeah. This mail just arrived to my "main" folder instead of "notmuch"
one, as you kept me in CC and hence Mailman did not send the copy with
List-Id to me.

Please read the whole thread.

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: 



[notmuch] [PATCH 1/2] Close message file after parsing message headers

2009-11-17 Thread Mikhail Gusarov
Keeping unused files open helps to see "Too many open files" often.

Signed-off-by: Mikhail Gusarov 
---
 lib/message-file.c |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/lib/message-file.c b/lib/message-file.c
index 8a3f8ee..197ab01 100644
--- a/lib/message-file.c
+++ b/lib/message-file.c
@@ -325,6 +325,11 @@ notmuch_message_file_get_header (notmuch_message_file_t 
*message,
return decoded_value;
 }

+if (message->parsing_finished) {
+fclose (message->file);
+message->file = NULL;
+}
+
 if (message->line)
free (message->line);
 message->line = NULL;
-- 
1.6.3.3



Use of strcasestr

2010-04-13 Thread Mikhail Gusarov

Twas brillig at 15:58:10 12.04.2010 UTC+02 when tom at dbservice.com did gyre 
and gimble:

 TC> In 4fd9ea0 (guess From address from Received headers, 2010-04-06) you 
introduced
 TC> strcasestr, which is not portable, see 82e47ec (notmuch reply: Use strstr
 TC> instead of strcasestr for portability., 2010-02-04).

 TC> Is strcasestr really necessary there or can it be replaced with strstr?

strcasecmp is POSIX.1-2001.

If you know any OS which does not have it, add a new file to compat/ subdir.

-- 
  http://fossarchy.blogspot.com/
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: