commit 938f43a2d04f3806ac8f539594dd1bd6197c3449
parent 3eec02ee1af607631e0a49b8321f2c5283ad908f
Author: Jaromil <jaromil@dyne.org>
Date:   Thu,  1 Jan 2015 15:50:48 +0100
refinements to delivery
Diffstat:
4 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/src/zlibs/filters b/src/zlibs/filters
@@ -135,7 +135,8 @@ EOF
     # create the notmuch database if not present
     [[ -r "$MAILDIRS"/cache/notmuch/rc ]] || {
         notice "Indexing emails in the search database"
-        nm_index
+        nm setup
+        nm new
     }
 
     # compile the list of own addresses and aliases
diff --git a/src/zlibs/helpers b/src/zlibs/helpers
@@ -51,6 +51,18 @@ isemail() {
    return $?
 }
 
+ismailinglist() {
+    _head=`awk '{ print $0 }
+/^$/ { exit }'`
+    [[ "$_head" =~ "List-Id" ]] \
+        || [[ "$_head" =~ "X-BeenThere" ]] \
+        || [[ "$_head" =~ "List-Post" ]] \
+        || [[ "$_head" =~ "X-Mailman-Version" ]] \
+        || [[ "$_head" =~ "Mailing-List" ]] \
+        && return 0
+    return 1
+}
+        
 # parses stdin and converts some characters to html
 escape_html() {
     sed -e '
diff --git a/src/zlibs/maildirs b/src/zlibs/maildirs
@@ -207,8 +207,8 @@ merge() {
 }
 
 
-# very simple LDA delivery to a maildir
-# the delicate part is returning all errors
+# LDA delivery to a maildir
+# important to return 1 on all errors
 # so that fetchmail does not deletes mail from server
 deliver() {
     if [ "$1" = "" ]; then
@@ -270,7 +270,14 @@ deliver() {
         return $?
     }
 
+    _email=`cat`
+    print "$_email" | ismailinglist
+    [[ $? = 0 ]] && {
+        print "$_email" | nm insert --folder="$dest" +filters +mailinglist
+        return $?
+    }
+
     # anything else +filters
-    cat | nm insert --folder="$dest" +filters
+    print "$_email" | nm insert --folder="$dest" +filters
     return $?
 }
diff --git a/src/zlibs/search b/src/zlibs/search
@@ -27,6 +27,7 @@
 
 # internal use
 nm() {
+    func "notmuch $@"
     [[ -r "$MAILDIRS"/cache/notmuch/rc ]] || nm_setup
     notmuch --config="$MAILDIRS"/cache/notmuch/rc ${@}
     _res=$?
@@ -87,15 +88,10 @@ nm_index() {
     act "please wait, this may take a while..."
     nm_setup
     nm new
-    act "tagging inbox"
-    nm tag +inbox +priv folder:known
-    nm tag +inbox +priv folder:sent
-    act "tagging priv"
-    nm tag +priv folder:priv
-    act "tagging unsorted"
-    nm tag +unsorted folder:unsorted
-    nm tag +unsorted folder:unsorted.ml
-    nm tag +unsorted folder:lists.
+    nm tag +inbox +priv -unsorted folder:known
+    nm tag +inbox +priv -unsorted folder:sent
+    nm tag -inbox +priv -unsorted folder:priv
+    nm tag -inbox -priv +unsorted folder:unsorted
     act "compressing database"
     nm compact
     notice "Indexing completed"
@@ -173,6 +169,10 @@ user_agent = Jaro Mail <http://jaromail.dyne.org>
     translated = ⚷
   [[signed]]
     translated = ✍
+  [[filters]]
+    translated = ⚙
+  [[mailinglist]]
+    translated = ☰
 EOF
 
     alot -c "$MAILDIRS"/cache/alot/rc -n "$MAILDIRS"/cache/notmuch/rc \