Package: lbdb
Version: 0.35~y1
Severity: wishlist
Tags: patch

I've found lbdb's m_inmail hard to use since my list was expanding
rapidly due to spam/mailing lists/etc. And although spam is under
control pretty much, it still grows - receipts, promotions, occasional
spam, etc.

So I've decided to add a feature: limit email addresses stored in the
list only to frequently used (or which were frequently used once) or
which are newish (ie they might not had a chance yet to become
frequently used). So, I've patched munge which is used by m_inmail.
Actually I've started my work from munge-keeporder, but now
munge-keeporder is not necessary: munge was parametrized, so it can do
either way, thus please pay caution while applying patch.

I hope you or upstream would find it useful. Default behavior must be as
it is now, just that it would add a count at the end of each entry in
the list.

-- System Information:
Debian Release: 4.0
  APT prefers unstable
  APT policy: (990, 'unstable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.18-1-686
Locale: LANG=ru_RU.KOI8-R, LC_CTYPE=ru_RU.KOI8-R (charmap=KOI8-R)

Versions of packages lbdb depends on:
ii  libc6                        2.3.6.ds1-9 GNU C Library: Shared libraries
ii  libvformat1                  1.13-4      Library to read and write vcard fi
ii  perl                         5.8.8-7     Larry Wall's Practical Extraction 

lbdb recommends no packages.

-- no debconf information
diff -x '*~' -Naur lbdb-0.34.orig/configure lbdb-0.34/configure
--- lbdb-0.34.orig/configure    2005-10-29 08:49:48.000000000 -0400
+++ lbdb-0.34/configure 2007-01-09 12:49:51.000000000 -0500
@@ -4919,7 +4919,7 @@
 
 
 
-                                                                               
                                                             
ac_config_files="$ac_config_files Makefile lbdbq.sh munge.awk 
munge-keeporder.awk lbdb-fetchaddr.sh lbdb-munge.sh lbdb_lib.sh 
nodelist2lbdb.pl palm_lsaddr.pl mutt_ldap_query.pl $MODULES_SH $TACAWK 
lbdb.spec lbdb.rc"
+                                                                               
                                                             
ac_config_files="$ac_config_files Makefile lbdbq.sh munge.awk lbdb-fetchaddr.sh 
lbdb-munge.sh lbdb_lib.sh nodelist2lbdb.pl palm_lsaddr.pl mutt_ldap_query.pl 
$MODULES_SH $TACAWK lbdb.spec lbdb.rc"
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
 # tests run on this system so they can be shared between configure
@@ -5474,7 +5474,6 @@
   "Makefile" ) CONFIG_FILES="$CONFIG_FILES Makefile" ;;
   "lbdbq.sh" ) CONFIG_FILES="$CONFIG_FILES lbdbq.sh" ;;
   "munge.awk" ) CONFIG_FILES="$CONFIG_FILES munge.awk" ;;
-  "munge-keeporder.awk" ) CONFIG_FILES="$CONFIG_FILES munge-keeporder.awk" ;;
   "lbdb-fetchaddr.sh" ) CONFIG_FILES="$CONFIG_FILES lbdb-fetchaddr.sh" ;;
   "lbdb-munge.sh" ) CONFIG_FILES="$CONFIG_FILES lbdb-munge.sh" ;;
   "lbdb_lib.sh" ) CONFIG_FILES="$CONFIG_FILES lbdb_lib.sh" ;;
diff -x '*~' -Naur lbdb-0.34.orig/configure.in lbdb-0.34/configure.in
--- lbdb-0.34.orig/configure.in 2005-10-29 08:41:45.000000000 -0400
+++ lbdb-0.34/configure.in      2007-01-09 12:42:04.000000000 -0500
@@ -198,6 +198,6 @@
 AC_SUBST(LBDB_VERSION)
 
 AC_SUBST(MODULES)
-AC_OUTPUT(Makefile lbdbq.sh munge.awk munge-keeporder.awk lbdb-fetchaddr.sh \
+AC_OUTPUT(Makefile lbdbq.sh munge.awk lbdb-fetchaddr.sh \
        lbdb-munge.sh lbdb_lib.sh nodelist2lbdb.pl palm_lsaddr.pl \
        mutt_ldap_query.pl $MODULES_SH $TACAWK lbdb.spec lbdb.rc)
diff -x '*~' -Naur lbdb-0.34.orig/lbdb-munge.sh.in lbdb-0.34/lbdb-munge.sh.in
--- lbdb-0.34.orig/lbdb-munge.sh.in     2005-10-29 10:48:09.000000000 -0400
+++ lbdb-0.34/lbdb-munge.sh.in  2007-01-09 12:40:52.000000000 -0500
@@ -3,7 +3,8 @@
 # -*-sh-*-
 #
 #     Copyright (C) 1999-2005  Roland Rosenfeld <[EMAIL PROTECTED]>
-# 
+#        Modified in 2007 by Yaroslav Halchenko <[EMAIL PROTECTED]>
+#
 #     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 2 of the License, or
@@ -29,13 +30,14 @@
 [EMAIL PROTECTED]@
 [EMAIL PROTECTED]@/fetchaddr
 db=$HOME/.lbdb/m_inmail.list
+munge="${prefix}/lib/lbdb/munge"
 
-if [ "$SORT_OUTPUT" = "false" -o "$SORT_OUTPUT" = "no" ]
-then
-    [EMAIL PROTECTED]@/munge-keeporder
-else
-    [EMAIL PROTECTED]@/munge
-fi
+[ "$SORT_OUTPUT" = "false" -o "$SORT_OUTPUT" = "no" ] && \
+    munge_options="keeporder=1"
+[ ! -z "$MUNGE_LIMITCOUNT" ] && \
+       munge_options="$munge_options${munge_options:+ 
}limitcount=$MUNGE_LIMITCOUNT"
+[ ! -z "$MUNGE_LIMITDATE" ]  && \
+       munge_options="$munge_options${munge_options:+ 
}limitdate=${MUNGE_LIMITDATE// /_}"
 
 if [ ! -f $db.dirty ]; then
     # Nothing to do
@@ -50,7 +52,7 @@
   exit 1
 fi
 
-if $munge < $db > $db.$$.tmp 2>/dev/null
+if $munge ${munge_options} < $db > $db.$$.tmp
 then
     # only move, if munge successful:
     mv -f $db.$$.tmp $db
diff -x '*~' -Naur lbdb-0.34.orig/lbdbq.sh.in lbdb-0.34/lbdbq.sh.in
--- lbdb-0.34.orig/lbdbq.sh.in  2006-08-19 04:07:50.000000000 -0400
+++ lbdb-0.34/lbdbq.sh.in       2007-01-09 12:49:00.000000000 -0500
@@ -81,7 +81,7 @@
        ;;
     *)
        MUNGE=$libdir/munge
-       MUNGE_KEEPORDER=$libdir/munge-keeporder
+       MUNGE_KEEPORDER="$libdir/munge keeporder=1"
        ;;
 esac
 
diff -x '*~' -Naur lbdb-0.34.orig/lbdb.rc.in lbdb-0.34/lbdb.rc.in
--- lbdb-0.34.orig/lbdb.rc.in   2006-10-14 08:10:42.000000000 -0400
+++ lbdb-0.34/lbdb.rc.in        2007-01-09 12:35:41.000000000 -0500
@@ -188,3 +188,18 @@
 # names or different comment fields)?  Default is "no".
 #
 #KEEP_DUPES=no
+
+#
+# Do you want to automatically remove outdated and infrequently used
+# entries collected by m_inmail?
+# Following date parameter specify the date before which (ie being
+# older) only those entries survive, which were seen by m_inmail more
+# than a specified times. Since rc is parsed on every libdbq
+# invocation, we can use date command to specify dynamic range as "-1
+# month". By default we keep entries which were seen at 3 times,
+# or younger than 1 month
+#
+# Note: KEEP_DUPES must be "no"
+#
+#MUNGE_LIMITCOUNT=3
+#MUNGE_LIMITDATE=`date --date='-1 month' +"%F %R"
diff -x '*~' -Naur lbdb-0.34.orig/Makefile.in lbdb-0.34/Makefile.in
--- lbdb-0.34.orig/Makefile.in  2005-10-29 10:48:08.000000000 -0400
+++ lbdb-0.34/Makefile.in       2007-01-09 12:50:20.000000000 -0500
@@ -41,7 +41,7 @@
 [EMAIL PROTECTED]@
 
 ALL=lbdbq lbdb_lib lbdb-fetchaddr lbdb-munge fetchaddr qpto8bit munge \
-       munge-keeporder nodelist2lbdb palm_lsaddr mutt_ldap_query lbdbq.man \
+       nodelist2lbdb palm_lsaddr mutt_ldap_query lbdbq.man \
        lbdb-fetchaddr.man nodelist2lbdb.man mutt_ldap_query.man lbdb.rc \
        $(MODULES) $(DOTLOCK_TARGET) $(TACTARGET)
 
@@ -61,7 +61,6 @@
        $(INSTALL) -m 755 lbdb_lib $(install_prefix)$(libdir)
        $(INSTALL) -m 755 munge $(install_prefix)$(libdir)
        $(INSTALL) -m 644 lbdb_bbdb_query.el $(install_prefix)$(libdir)
-       $(INSTALL) -m 755 munge-keeporder $(install_prefix)$(libdir)
        if [ "$(PERL)" != "no" ]; then \
                $(INSTALL) -m 755 nodelist2lbdb $(install_prefix)$(bindir); \
                $(INSTALL) -m 644 nodelist2lbdb.man \
@@ -131,10 +130,6 @@
        cat munge.awk > $@
        chmod a+x $@
 
-munge-keeporder: $(srcdir)/munge-keeporder.awk
-       cat munge-keeporder.awk > $@
-       chmod a+x $@
-
 mutt_ldap_query.man: $(srcdir)/mutt_ldap_query.pl
        if [ "$(PERL)" != "no" ]; then \
                pod2man mutt_ldap_query.pl > $@; \
@@ -160,7 +155,7 @@
        fi
 
 clean:
-       -rm -f *.o *~ $(ALL) munge.awk munge-keeporder.awk tac.awk \
+       -rm -f *.o *~ $(ALL) munge.awk tac.awk \
                nodelist2lbdb.pl palm_lsaddr.pl mutt_ldap_query.pl lbdb_dotlock
        -rm -rf ABQuery/sym ABQuery/obj
 
diff -x '*~' -Naur lbdb-0.34.orig/m_inmail.sh.in lbdb-0.34/m_inmail.sh.in
--- lbdb-0.34.orig/m_inmail.sh.in       2005-10-29 10:48:09.000000000 -0400
+++ lbdb-0.34/m_inmail.sh.in    2007-01-09 12:16:18.000000000 -0500
@@ -27,7 +27,7 @@
 
 m_inmail_query()
 {
-       export SORT_OUTPUT
+       export SORT_OUTPUT MUNGE_LIMITDATE MUNGE_LIMITCOUNT
        $libdir/lbdb-munge
        test -f $m_inmail_db  || return
        grep -ia "[EMAIL PROTECTED]" $m_inmail_db
diff -x '*~' -Naur lbdb-0.34.orig/munge.awk.in lbdb-0.34/munge.awk.in
--- lbdb-0.34.orig/munge.awk.in 2005-10-29 10:48:11.000000000 -0400
+++ lbdb-0.34/munge.awk.in      2007-01-09 12:50:40.000000000 -0500
@@ -3,34 +3,73 @@
 # -*-awk-*-
 #
 #     Copyright (C) 1998-2000  Thomas Roessler <[EMAIL PROTECTED]>
-#                   2000-2005  Roland Rosenfeld <[EMAIL PROTECTED]>
-# 
+#                        2000  Roland Rosenfeld <[EMAIL PROTECTED]>
+#     Modified in 2007 by Yaroslav Halchenko <[EMAIL PROTECTED]>
+#
 #     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 2 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, write to the Free Software Foundation,
 #     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,, USA.
 #
-# $Id: munge.awk.in,v 1.7 2005-10-29 14:48:11 roland Exp $
+# $Id: munge.awk.in,v 1.3 2005-10-29 14:48:11 roland Exp $
+
+function print_line (line, lastdate, count)
+{
+    if (line == "") return;
+       sub(/ /, "_", lastdate);    # to overcome bash command line problems in 
lbdb-munge
+    if (limitdate != "" && lastdate < limitdate && count < limitcount) return;
+    print line, FS, count;
+}
 
 BEGIN {
+    # initialization
     FS = "\t";
+    i = 0;
+
+    # default settings
+    keeporder = 0;              # do not keep order by default
+    limitdate = "0000-00-00_00:00"; # keep all dates by default
+    limitcount = 0;             # and do not limit by count by default
 }
 
 {
-    line[$1] = $0;
+    line[$1] = ($1 FS $2 FS $3);
+
+    if (lastdate[$1] == "" || lastdate[$1] < $3)
+        lastdate[$1] = $3;
+
+    line[$1] = ($1 FS $2 FS lastdate[$1]);
+
+    if (line[$4] != "")
+        cnt[$1] += line[$4];
+    else
+        cnt[$1]++;
+
+    if (keeporder == 1)
+    {
+        pos[$1] = i;
+        idx[i++] = $1;
+    }
 }
 
 END {
-    for (a in line) {
-       print line[a];
-    }
+    if (keeporder == 1)
+        for (j = 0; j < i; j++) {
+            if (pos[idx[j]] == j) {
+                print_line(line[idx[j]], lastdate[idx[j]], cnt[idx[j]]);
+            }
+        }
+    else
+        for (a in line) {
+            print_line(line[a], lastdate[a], cnt[a]);
+        }
 }
diff -x '*~' -Naur lbdb-0.34.orig/munge-keeporder.awk.in 
lbdb-0.34/munge-keeporder.awk.in
--- lbdb-0.34.orig/munge-keeporder.awk.in       2005-10-29 10:48:11.000000000 
-0400
+++ lbdb-0.34/munge-keeporder.awk.in    1969-12-31 19:00:00.000000000 -0500
@@ -1,41 +0,0 @@
-#! @AWK@ -f
-#
-# -*-awk-*-
-#
-#     Copyright (C) 1998-2000  Thomas Roessler <[EMAIL PROTECTED]>
-#                        2000  Roland Rosenfeld <[EMAIL PROTECTED]>
-# 
-#     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 2 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, write to the Free Software Foundation,
-#     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,, USA.
-#
-# $Id: munge-keeporder.awk.in,v 1.3 2005-10-29 14:48:11 roland Exp $
-
-BEGIN {
-    FS = "\t";
-    i = 0;
-}
-
-{
-    line[$1] = $0;
-    pos[$1] = i;
-    idx[i++] = $1;
-}
-
-END {
-    for (j = 0; j < i; j++) {
-       if (pos[idx[j]] == j) {
-           print line[idx[j]];
-       }
-    }
-}

Reply via email to