1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#! @SH@
#
# -*-sh-*-
#
# Copyright (C) 2000 Gabor Fleischer <flocsy@mtesz.hu>
#
# 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
#
# $Id: m_pine.sh.in,v 1.8 2002/02/11 19:23:53 roland Exp $
# m_pine for lbdb v0.9 by Gabor Fleischer <flocsy@mtesz.hu>
#
# Two variabled can be set in lbdbrc: PINERC, PINE_ADDRESSBOOKS
# Here comes the explanation what are they for:
# 1. First I look for $PINERC. If not set, then I use my defaults:
# PINERC="/etc/pine.conf /etc/pine.conf.fixed .pinerc"
# If you don't want me to look in the default PINERCs, then set PINERC=no
# 2. I make a list of all the addressbooks in the PINERCs.
# 3. Then the $PINE_ADDRESSBOOKS are added to this list.
# 4. And if this list is still empty then add the default addressbooks:
# PINE_ADDRESSBOOKS="/etc/addressbook .addressbook"
# 5. Make the query in the listed addressbooks
#
# Changelog:
# 0.9: Convert Quoted-Printable in the real names into plain 8bit.
# 0.8: When the 'real name' is missing, put " " there, so mutt works fine.
# 0.7: Fixed bugs:
# * Search was case sensitive. Now it's insensitive.
# * Lines with missing fields (i.e."nick<tab><tab>addr") were broken.
# * Default didn't work if address-books in pinercs were "".
# 0.6: The .addressbook format's multi-line addresses are supported.
# 0.5: Initial release.
#
AWK=@AWK@
prefix=@prefix@
exec_prefix=@exec_prefix@
qpto8bit=@libdir@/qpto8bit
m_pine_query()
{
addressbooks=
if [ x$PINERC != xno ] ; then
for pinerc in ${PINERC:-/etc/pine.conf /etc/pine.conf.fixed .pinerc}
do
if [ $pinerc = ${pinerc#/} ] ; then
pinerc=$HOME/$pinerc
fi
if [ -f $pinerc ] ; then
addressbook=`\
$AWK 'BEGIN {SPACE="";} \
/^(global-)?address-book[ ]*=/ { \
sub("^(global-)?address-book[ ]*=",""); \
while (/[ ]*[^ ]+[ ]+([^ , ]+)[ ]*,/) { \
sub("[ ]*[^ ]+[ ]+",""); \
sub("[ , ].*",""); \
printf("%s%s",SPACE,$0); \
SPACE=" "; \
getline; \
} \
sub("[ ]*[^ ]+[ ]+",""); \
sub("[ ].*",""); \
printf("%s%s",SPACE,$0); \
SPACE=" "; \
}' < $pinerc`
fi
addressbooks="${addressbook# } ${addressbooks# }"
done
fi
addressbooks="${PINE_ADDRESSBOOKS} ${addressbooks# }"
addressbooks=${addressbooks# }
for file in ${addressbooks:=/etc/addressbook .addressbook} ; do
if [ $file = ${file#/} ] ; then
file=$HOME/$file
fi
if [ -f $file ]
then
cat $file | $qpto8bit | $AWK -v find="$@" '\
function out() { \
if (match(tolower(line),low_find)) {
#order: nick full addr fcc comm \
R[1] = "^[^ ]*"; \
R[2] = "^[^ ]* [^ ]*"; \
R[3] = "^[^ ]* [^ ]* \(?[^ ]*\)?"; \
R[4] = "^[^ ]* [^ ]* [^ ]* [^ ]*"; \
R[5] = "^[^ ]* [^ ]* [^ ]* [^ ]* [^ ]*"; \
beg = 1; \
for (i=1;i<=5;i++) { \
match(line,R[i]); \
A[i] = substr(line,beg,RLENGTH-beg+1); \
beg = RLENGTH+2; \
} \
if (A[2] == "") {A[2] = " "} \
if (match(A[3],/\(.*\)/)) {A[3] = substr(A[3],2,length(A[3])-2)} \
if (A[5] != "") {A[5] = " [" A[5] "]"} \
printf "%s %s %s%s (pine)\n",A[3],A[2],A[1],A[5]; \
} \
} \
BEGIN { \
FS=" "; \
low_find = tolower(find); \
getline; \
while (/^#DELETED/) {getline} ; \
line = $0 \
} \
$0 !~ /^#DELETED/ { \
if (/^ /) { \
gsub(" ",""); \
line = line $0; \
} else { \
out(); \
line = $0; \
} \
} \
END { \
out() \
}'
fi
done
}
|