<<< Date Index >>>     <<< Thread Index >>>

Re: Adding entries to ldap addressbook



On 2008-02-29, Nathan Huesken <mutt@xxxxxxxxxxxxxxx> wrote:

> On Wed, Feb 27, 2008 at 03:03:14PM -0600, Kyle Wheeler wrote:

> > On Wednesday, February 27 at 06:40 PM, quoth Nathan Huesken:
> > >I invoke the script this way:
> > >macro index,pager a '<shell-escape>~/add2ldap<enter>'
> > >
> > >It then asks me for the name and eMail (because they are not
> > >given as paramters).  So far so good, but I wonder if it is
> > >possible to automaticly extract name and sender from an eMail
> > >and pass them as parameters to add2ldap?
> > 
> > Sure, all you have to do is create a script that will extract those 
> > details.
> > 
> > If, for example, you have DJB's mess822 package installed, you could 
> > do something like this:
> > 
> >      #!/bin/bash
> >      FROM=`822field from`
> >      if [[ $FROM =~ "<*@*>" ]] ; then
> >          EMAIL=`sed 's/.*<\([^>]*\)>.*/\1/' <<<"$FROM"`
> >          NAME=`sed 's/ *\(.*\)  *<.*/\1/' <<<"$FROM"`
> >      else
> >          EMAIL="$FROM"
> >          NAME=""
> >      fi
> >      exec add2ldap "$NAME" "$EMAIL"
> > 
> > If you don't have the mess822 package, you can do something similar if 
> > you have the formail (part of the procmail package) binary handy. The 
> > equivalent command would be:
> > 
> >      FROM=`formail -c -x From`

> Hi,
> 
> Thansk, that makes a lot  of sense.
> Unfortantly, it does not yet work completly. I want the script to
> scan the eMail for default values, but afterwards ask the user to
> confirm or correct these default values.
> So the script needs to get the eMail from stdin, but also be
> intaractive with the user (utilizing the read command).
> 
> If I do:
> <pipe-message>script<enter>
> 
> The read command just exits, as if I press enter.
> Both
> <pipe-message><shell-escape>script<enter>
> 
> <shell-escape><pipe-message>script<enter>
> 
> Both do not work :(

You need to attach the stdin of add2ldap to your terminal.  There
are a couple of ways to do this.  One is to put this line

   exec < /dev/tty

in your script somewhere after stdin is read by 822field or formail.
This will redirect the stdin of the script from your terminal.
Another way is to redirect the stdin of just the add2ldap command
from your terminal, like this:

   exec add2ldap "$NAME" "$EMAIL" < /dev/tty

HTH,
Gary