Date: Sat, 9 Nov 2002 12:58:54 -0500 From: AlanE <alane@geeksrus.net> To: FreeBSD Ports List <ports@freebsd.org>, KDE-FreeBSD List <kde-freebsd@lists.csociety.org> Subject: Convert Mutt aliases to KMail (KDE) Addressbook Message-ID: <20021109175853.GA21662@wwweasel.geeksrus.net>
next in thread | raw e-mail | index | archive | help
I wrote this script that reads a mutt aliases file from stdin and produces a set of vcards on stdout. If you run it like: muttalias2vcard < ~/.mutt/aliases > ~/.kde/share/apps/kabc/std.vcf you'll have a pretty close copy of your mutt aliases for use with KMail. Going the other way wouldn't be too hard, either, but is of less use since, as near as I can find, KMail doesn't have a command to scrape an address out of a mail message and add it to the addressbook like mutt does. ==8<====8<====8<====8<====8<====8<====8<====8<====8<====8<== #!/usr/local/bin/ruby # -*-ruby-*- # # muttalias2vcard # # Copyright (c) 2002 Alan Eldridge. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # * Neither the name of the copyright owner nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # $Id: muttalias2vcard.in,v 1.2 2002/11/09 17:41:51 alane Exp $ # # 2002/11/08 alane@geeksrus.net # class Alias def initialize(a,e) @alias = a @email = e.delete('<>') end def to_s() "#{@alias} => <#{@email}>" end attr_reader :alias, :email end class Person def initialize(names) @names = names @alist = Array.new() end attr_reader :names, :alist end class AliasFile < Hash def initialize() super() end def add(names, malias) full = names.join(" ").strip() if !has_key?(full) names.unshift(names.pop()) store(full, Person.new(names)) end fetch(full).alist.push(malias) end def to_s() nlist = "" each { |full, person| alist = "" person.alist.each { |a| alist += "\t#{a}\n" } nlist += "#{full}:\n#{alist}" } nlist end def to_vcards() text = "" sort.each { |fullname, person| text += "BEGIN:VCARD\n" text += "VERSION:3.0\n" text += "FN:#{fullname}\n" text += "N:" person.names.each { |name| text += (name + ";") } if person.names.size < 4 text += (";" * (4 - person.names.size)) end text += "\n" person.alist.each { |a| text += "EMAIL:#{a.email}\n" } text += "END:VCARD\n" } text end end $afile = AliasFile.new() text = readlines().delete_if { |ln| %r{^\s*(\#|$)} =~ ln } text.each { |ln| vals = ln.split() vals.delete_at(0) a = vals.shift() e = vals.pop() $afile.add(vals, Alias.new(a, e)) } print $afile.to_vcards() #EOF ==8<====8<====8<====8<====8<====8<====8<====8<====8<====8<== -- Alan Eldridge Unix/C(++) IT Pro for 20 yrs, seeking new employment. (http://wwweasel.geeksrus.net/~alane/resume.txt) KDE, KDE-FreeBSD Teams (http://www.kde.org, http://freebsd.kde.org/) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021109175853.GA21662>