Subject: Re: Manipulating .addressbook, help requested

From: [email-masked] (Brian R. Hunt)
Date: 5 Dec 95 02:06:49 GMT

[email-masked] (Vikram Lall) writes:
>I am writing a shell script to add entries to aliases
>in the .addressbook file, but before I start, I wanted to
>run some things by you experts!

I'm no expert, but I've done some experimenting and am also interested
in any better suggestions, here is what I've learned.

>1. Will pine be okay with the .addressbook being written to?

Yes.

>2. Has this been done before, and do any scripts exist for
>   this sort of thing?

Simple aliases are stored one to a line in the format

nickname<TAB>Name, Full<TAB>address

where <TAB> denotes a control-I, it should not be hard to write a
script to add such lines.  What I am more interested in is maintaining
distribution lists in a one-address-per-line format.  I find I can do
so if I edit the addressbook outside of Pine and construct each list
like so:

listname<TAB>Name of List<TAB>(nobody,
   address1,
   address2,
   address3,
   )

with exactly 3 spaces at the start of every line but the first.  Then
I must be very careful not to do anything to cause Pine to rewrite the
addressbook itself, for instance by keeping my lists in a separate
addressbook, and turning off sorting of addressbook entries (either
that or make sure not to enter a new list which is out of alphabetical
order).

Of course if I am missing a simpler solution I would like to know...

-- 
Brian R. Hunt
[email-masked]

---

From: [email-masked] (Pierre Frenkiel)
Date: 5 Dec 1995 15:23:17 GMT

for people interested, I wrote 2 small scripts, ed_alias (58 lines)
and pine_to_elm(18 line)
here is the ed_alias help:

usage: ed_alias [ -? | -h ]\

     The program edits your personnal pine alias file (in your .pine directory)
     which must already exist(if not, create it with pine)
     Old version is saved in addressbook.bak1 and addressbook.bak1 is saved in
    addressbook.bak2

     Then, addressbook is translated into elm format, and result is written
     in your elm alias file (in your .elm directory).
     This step in only performed if you have already a file named aliases.text
    in this directory) You can then use either pine or elm withe same
     aliases.
     Old version is saved in aliases.text.bak

     Editing is done with the editor whose name is in variable EDITOR,
     or in variable VISUAL, if EDITOR is undefined.
     Default is vi.
     Reminder: the field separator for pine is the TAB character, instead
     of '=' for elm.

     This works correctly with pine only if you choose the option
     'don't sort' in the pine configuration

---

From: [email-masked] (R. Stewart Ellis)
Date: 6 Dec 95 01:53:38 GMT

[email-masked] (Edwin Kremer) writes:

 >In <[email-masked]> [email-masked] (Vikram Lall) writes:

 >   | I am writing a shell script to add entries to aliases
 >   | in the .addressbook file [...]

 >To simplify the transition from Elm to Pine, I wrote a silly Perl script
 >'elm2pine' to convert the aliases file. If you want it I can mail it to
 >you; if I get many requests, I'll post it here (it's small)

Please post.

 >		best regards,
 >						--[ Edwin ]--
 >--
 >Edwin H. Kremer, systems- and network administrator.   <[email-masked]>
 >Dept. of Computer Science,  Utrecht University, The Netherlands   [WHOIS: ehk3]
 >-------------------- http://www.cs.ruu.nl/people/edwin/ -----------------------

-- 
  R.Stewart(Stew) Ellis, Assoc.Prof., (Off)810-762-9765   ___________________
  Humanities & Social Science,  GMI Eng.& Mgmt. Inst.    /   _____  ______ 
  Flint, MI 48504      [email-masked]               /        / /  /  / /
  Web admin:  chimera,nn,tin,jove,kermit - free's best!/________/ /  /  / /

---

From: [email-masked] (Edwin Kremer)
Date: 5 Dec 1995 18:46:05 GMT

best regards,
						--[ Edwin ]--
-------------------- http://www.cs.ruu.nl/people/edwin/ -----------------------

---

From: [email-masked] (Edwin Kremer)
Date: 6 Dec 1995 15:40:12 GMT

In <[email-masked]> [email-masked] (R. Stewart Ellis) writes:

   | Please post.

Ok. See below.
No guarantees; it works for my users, it my work for you.

#!/bin/sh
# This is a shell archive (shar 3.32)
# made 10/07/1994 22:12 UTC by [email-masked]
#
# existing files WILL be overwritten
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   3564 -rwxr-xr-x elm2pine
#
if touch 2>&1 | fgrep 'amc' > /dev/null
 then TOUCH=touch
 else TOUCH=true
fi
# ============= elm2pine ==============
echo "x - extracting elm2pine (Text)"
sed 's/^X//' << 'SHAR_EOF' > elm2pine &&
X#!/net/bin/perl
X#---------------------------------------------------------------------------
X#	elm2pine - convert Elm-2.4 aliases file to Pine 3.90 format
X#	(writes result to standard-output)
X#
X# 1.0	EHK 02-Sep-94	from scratch
X# 1.1	EHK 03-Sep-94	fix continuation-line parsing bug, resulting in
X#			duplicate partial distribution-lists. Actually, I
X#			got the documentation wrong at first glance, so this
X#			is more of a major rewrite than just a bug fix...
X#---------------------------------------------------------------------------
X
X$P		= 'elm2pine' ;
X
X$home		= $ENV{'HOME'} || die "Can't find your HOME directory: $!" ;
X$elm		= "$home/.elm/aliases.text" ;
X
Xopen(ELM, "< $elm") || die "You don't have Elm aliases in your ~/.elm directory: $!" ;
X
X#---------------------------------------------------------------------------
X# Pass 1 : read the entire alias file in core; do some minimal processing
X#---------------------------------------------------------------------------
Xprint STDERR "$P: Pass 1 -- reading aliases '$elm'...\n" ;
Xwhile ( <ELM> ) {
X	chop ;
X	next if ( /^$/ || /^#/ ) ;	# skip comment and blank lines
X
X	# delete blanks around the Elm aliases field-seperator '='
X	# and around the Elm-specials ',' and ';'
X	s/\s*([=,;])\s*/\1/g ;
X
X	# if we have leading blanks, this must be a continuation line
X	if ( /^[\t\s]/ ) {
X		# which we can only have if we've seen a nickname already
X		if ( ! defined($nickname) ) {
X			print STDERR "$P: ERROR: continuation line without prefix ignored: '$_' \n" ;
X			next ;
X		}
X
X		s/^\s+// ;			# get rid of the leading blanks
X		$alias{$nickname} .= "$_" ;
X		$clines++ ;
X	}
X	else {
X		if ( $clines ) {
X			print STDERR "$P:      [OK]  $clines continuation-line(s) joined.\n" ;
X			$clines = 0 ;
X		}
X		undef($nickname);
X		($nickname, $fullname, $address) = split(/=/) ;
X		$fullname = "*none-given*" if ( $fullname eq '' ) ;
X
X		# Elm has multiple-nicknames, so we have to duplicated
X		# them for Pine to maintain the same information
X		@nnames = split(/,/, $nickname) ;
X		if ( $#nnames > 0 ) {
X			$multi_aliases = $#nnames + 1 ;
X			print STDERR "$P:      [OK]  $multi_aliases multiple-aliases duplicated.\n" ;
X		}
X		foreach $nname ( @nnames ) {
X					$alias{$nname} = "$fullname#$address" ;
X				}
X	}
X}
Xclose(ELM) ;
X
X#---------------------------------------------------------------------------
X# Pass 2 : convert to Pine format. Add default Fcc-field, optional comment
X#	   and apply Pine semantics to Elm-special chars ';' and ','
X#---------------------------------------------------------------------------
Xprint STDERR "$P: Pass 2 -- converting Elm aliases to Pine format...\n" ;
X$aliasc = 0 ;
Xforeach $nickname (sort keys(%alias)) {
X	$_ = $alias{$nickname} ;
X	$aliasc++ ;
X
X	( $fullname, $addrlist ) = split(/\#/) ;
X
X	# anything after a ',' in the fullname is optional comment
X	if ( $fullname =~ /,/ ) {
X		$fullname =~ s/(.*),(.*)/\1/ ;
X		$comment = "$2" ;
X	}
X	else {
X		$comment = '' ;
X	}
X
X	# a ';' in the fullname for Elm, must be a ',' for Pine
X	$fullname =~ s/;/, / ;
X
X	# distribution-list aliases need brackets
X	$addrlist = "(" . "$addrlist" . ")" if ( $addrlist =~ /,/ ) ;
X
X	# output as Pine aliases now:
X	#	<nickname>TAB<fullname>TAB<address>TAB<fcc>TAB<comment>
X	# [Aaaaaaaaaarrrrggggggggggggghhhhhh.... why the !&^@#$^$% `TAB' :--(
X
X	$, = "\t" ;
X	print $nickname, $fullname, $addrlist ;
X
X	# if we have a comment-field, we will put in a Fcc-field as well
X	print "\t$nickname\t$comment" if ($comment ne '') ;
X	print "\n" ;
X}
X
Xprint STDERR "$P:      [OK]  successfully converted $aliasc aliases.\n" ;
X
Xexit 0 ;
X
X__END__
SHAR_EOF
$TOUCH -am 0903221994 elm2pine &&
chmod 0755 elm2pine ||
echo "restore of elm2pine failed"
set `wc -c elm2pine`;Wc_c=$1
if test "$Wc_c" != "3564"; then
	echo original size 3564, current size $Wc_c
fi
exit 0

						--[ Edwin ]--
-------------------- http://www.cs.ruu.nl/people/edwin/ -----------------------

---

From: [email-masked] (R. Stewart Ellis)
Date: 6 Dec 95 01:52:29 GMT

>     'don't sort' in the pine configuration

Please post or give an ftp site or URL.