Re: Can I query a KAddressBook?
- To: mutt-users@xxxxxxxx
- Subject: Re: Can I query a KAddressBook?
- From: mimosinnet@xxxxxxxxx
- Date: Thu, 14 Aug 2008 22:56:16 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:date:to:subject :message-id:reply-to:mail-followup-to:mime-version:content-type :content-disposition:user-agent:from; bh=K2/wkOPVwWO1LSWUScpKhHFPTek87UUmqs5qiTlDwi0=; b=HWyXF/GHs56PMYJGMoqy/kpwyvAM1SdD7UrzkTlH87oNZKOcHHaHNU8gpiHcg348Kh kVkXnG8oNsdq+YkufK8PPzahppmckd6PC+5eNum2tKorOJshCFSuB1/v1sByfY8GtSly Y2f9CTumGqLpNLUXRqIQxMdZySFRup8rQBCp8=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:to:subject:message-id:reply-to:mail-followup-to:mime-version :content-type:content-disposition:user-agent:from; b=dQLYjcwpczkMmmjR5oVH9S4yATl2NG/9wsKjQ1e3gj+v7xO0by7UlL6H77TEcy3Syg OLmtHt/+S+ANIG4OG7D8+xp0ICZAetoL7fQbLHMpDXdOsh3iXJbU5vo7q//zGe66OQQJ UOK8orUa7MHhpEy/QJ5uRIf5woya4Xt0u3MIE=
- List-post: <mailto:mutt-users@mutt.org>
- List-unsubscribe: send mail to majordomo@mutt.org, body only "unsubscribe mutt-users"
- Mail-followup-to: mutt-users@xxxxxxxx
- Reply-to: "mutt-users@xxxxxxxx"@localhost
- Sender: owner-mutt-users@xxxxxxxx
- User-agent: Mutt/1.5.16 (2007-06-09)
I am moving from kmail
to mutt, and I am having problems converting from kaddressbook to abook.
Basically, when a contact has many e-mail addresses, only one is passed
to abook.
Meanwhile, I was wondering if it would be possible to query
kaddressbook.
I have found the following script in this web page:
http://wahjava.wordpress.com/2007/05/28/kaddressbook-in-mutt/
and I think it would be rellevant to have it in the list (the link at
the original version is not available). I have tried
the script and it works all right.
Cheers!
=======================
#!/usr/bin/env python
# Original version at: http://shove-it.de/open/jcm/muttquery.py
###############################################
# answer queries for mutt from kabc file
###############################################
import sys
import os
import re
KDE_ADDRESSBOOK=os.environ['HOME'] + '/.kde/share/apps/kabc/std.vcf'
# String to identify Mail address entrys in vcards
MAIL_INIT_STRING = r'EMAIL(?:;TYPE=PREF)?:'
# String to identify Name entrys in vcards
NAME_INIT_STRING = r'(?:F)?N:'
class vcard:
def __init__(self, email, name):
self.email = str(email)
self.name = str(name)
def parseFile(file_name):
if not os.access(file_name, os.F_OK|os.R_OK):
print 'Cannot open file ' , file_name
sys.exit(1)
try:
cf = open(file_name)
cards = cf.read()
finally:
cf.close()
re_vcard = re.compile(r'BEGIN:VCARD.*?END:VCARD', re.DOTALL)
vcards = re_vcard.findall(cards)
return vcards
def getMatches(vcards, search_string):
lines = []
search_re = re.compile(search_string, re.I)
mail_re = re.compile(r'^' + MAIL_INIT_STRING + r'(.*)$', re.MULTILINE)
name_re = re.compile(r'^' + NAME_INIT_STRING + r'(.*)$', re.MULTILINE)
for loop_vcard in vcards:
if search_re.search(loop_vcard):
if mail_re.search(loop_vcard) != None:
tmp_mail = mail_re.findall(loop_vcard)
if name_re.search(loop_vcard) != None:
tmp_name = name_re.search(
loop_vcard).group(1).replace(';', ' ').strip()
else:
tmp_name = ''
for mail in tmp_mail:
my_vcard = vcard(mail.strip(), tmp_name)
lines.append(my_vcard)
return lines
# main program starts here
vcards = parseFile(KDE_ADDRESSBOOK)
try:
search_string = sys.argv[1]
except IndexError:
print 'Use only with an argument'
sys.exit(1)
lines = getMatches(vcards, search_string)
print 'Searched ' + str(vcards.__len__()) + ' vcards, found ' + str(
lines.__len__())+ ' matches.'
for line in lines:
#tmp_fill = (40 - line.email.__len__() ) * ' '
print '%s\t%s' % (line.email, line.name)
#print '%s' % line.email,
if lines.__len__() > 0:
sys.exit(0)
else:
sys.exit(1)
--
Location: 41:24:51N (41.41417) 2:11:25E (2.1903)
Linux User: #463211