Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Lotus Notes address book export browser

by greenFox (Vicar)
on Jun 10, 2003 at 05:55 UTC ( [id://264547]=sourcecode: print w/replies, xml ) Need Help??
Category: Miscellaneous
Author/Contact Info Murray Barton <muzza at iinet dot net dot au>
Description: As I spend most of my time in cygwin with an xterm to some unix host or another swapping back to Notes for a phone number seemed like a pain :) I added the number matching facility to help auditing my phone bill.
#!/usr/bin/perl -w
#
# address.pl
#
# -h to print the help doco
#
# to generate the export of the notes address book, go to
# address book, 
# file->export-> <choose file name> ->export -> 
# <replace if file already exists> -> 
# <select all documents> <select character code 12> 
# <select wrap width=75> ->OK
#

use strict;
use Getopt::Std;

my %settings = ( 
  debug => 0,
  print_fields => ["CompanyName", "OfficePhoneNumber", 
                   "CellPhoneNumber", "PhoneNumber", 
                   "MailAddress", "OfficeFAXPhoneNumber"],
  number_srch      => 0,
  print_all_fields => 0,
);

# $settings->{print_fields}: we will print these if they have a value

{
  my %args;
  local $SIG{'__WARN__'} = sub { print "$_[0]\n"; help(); exit 1; };
  getopts("n:ha", \%args);
  $args{h} and do { help(); exit; };
  $settings{number_srch}      = $args{n} if $args{n};
  $settings{print_all_fields} = 1        if $args{a};
}

my $address_file = $ENV{'HOME'} . '/dev/docs/address.txt' ;
my @addresses;
read_address_file($address_file);

my $pattern = $ARGV[0] || '.*';
$pattern =~ s/(?<!\.)\*/\.\*/g;
$pattern = '\b' . $pattern;

print "[$pattern]\n" if $settings{debug};

for my $record ( @addresses ){
    
  if ( $settings{number_srch} ){
    for ( @{$settings{print_fields}} ){
      if ( $record->{$_} =~ /$settings{number_srch}/ ){
        print_record($record);
    last;
      }
    }
    next;
  }
    
  if ( $record->{FullName} =~ /$pattern/i ){
    print_record($record);
  }
}
exit;

sub print_record {
  my $record = $_[0];
  my $full_name = $record->{FullName};
  $full_name = parse_full_name($full_name) if ( $full_name =~ /,/ );
  print $full_name, ":\n";
    
  unless ($settings{print_all_fields}){
    for ( @{$settings{print_fields}} ){
      my $value = $record->{$_};
      # don't print the company name if it is "personal"
      next if ( /^CompanyName$/ and $value =~ /^personal$/i );
      printf "\t%-20s: %s\n", $_, $value if ( $value );
    }

    # notes can give them an InternetAddress instead of a MailAddress.
+..
    if ( ! $record->{MailAddress} ){
      my $value = $record->{InternetAddress};
      printf "\t%-20s: %s\n", 'InternetAddress', $value if ( $value );
    }
    return;
  }

  # print everything!
  for (keys %{$record}){
    my $value = $record->{$_};
    printf "\t%-20s: %s\n", $_, $value if ( $value );
  }
}


sub read_address_file {
    
  my $address_file = shift || die "You didn't tell me the name of the 
+address file!\n";
  my @temp=();
    
  open(ADDRESS, $address_file) || die "Could not open $address_file: $
+!\n";
  while (<ADDRESS>){
    s/\r//g;
    s/\s*$//;
    chomp;
    my $rec={};
    if (/^\s*$/ ){  # whitespace record delimiter...
      next if (! @temp);
      for my $fields (@temp){
        my ($field, $value) = split /:\s*/, $fields;
        $value =~ s/\s+/ /g;
        $rec->{$field} = $value;
        if ( $field eq "FullName" ){
          $value =~ s/[\s\W]//g;
          $rec->{SortName} = lc ($value);
        }
      }    
      push @addresses, $rec;
      @temp = ();
      next;
    }
    push @temp, $_;
  }
  close(ADDRESS);
  @addresses = sort { $a->{SortName} cmp $b->{SortName} } @addresses;
}

sub parse_full_name {
# sometimes lotus does odd things to the name... 
  my $name = shift || die "sub parse_full_name did not get a parameter
+\n";
  my @bits = split /,/, $name;

  for (@bits){
    next if /\./;
    next if /@/;
    next if /=/;
    next unless /\s+/;
    $name = $_;
  }
  return $name;
}

sub help {
  print "$0: [-n number] [-h] [-a] \"name_pattern\"\n";
  print "\tname pattern: case insensitive, understands *, over-ridden 
+by -n\n";
  print "\t-n matches numerically against number\n";
  print "\t-h prints this message\n";
  print "\t-a print all fields not just the default ones\n";
}
Replies are listed 'Best First'.
Re: Lotus Notes address book export browser
by WhiteBird (Hermit) on Jun 10, 2003 at 20:31 UTC
    ++ This works very nicely. Thanks for providing it. I have 3 options of where/how to export my Lotus Address Book, and I exported to the Structured Text option which worked perfectly.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://264547]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-26 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found