From: gamin@ireq-robot.hydro.qc.ca (Martin Boyer)
Newsgroups: gnu.emacs.vm.bug
Subject: Re: vm gives "User unknown" error when recipient is yp alias
Date: 28 Sep 92 17:10:55 GMT
Organization: Le laboratoire de robotique de l'Institut de recherche
	d'Hydro-Quebec

>>>>> Milo Chan writes:

>When I specify a To: recipient which is actually a yp alias, vm gives the
>message to sendmail with "-t", which tells sendmail to search the message
>for recipients.  Although sendmail *does* send the message to the correct
>recipients, it also returns a "User unknown" error

It's a sendmail bug.  Sun assigned it the bug ids 1041284 and 1030316.
I wrote the following Perl wrapper for sendmail.  It parses the
addresses in the message and puts them on the command line before
actually sending the message to sendmail.  To use it, put the
following line in your .emacs:

(setq sendmail-program "/local/bin/sendmail-fix")
                        ^^ Set this according to your system.


#!/usr/bin/perl
# ---Le laboratoire de robotique de l'Institut de recherche d'Hydro-Quebec-----
# 
# Nom     : sendmail-fix [sendmail options]
# Fonction: Wrapper to fix the SunOS 4.1.1 defective sendmail.
# Fichiers: sendmail-fix.pl
# Notes   : In emacs, use (setq sendmail-program "..../sendmail-fix")
# 
# Cree    :  3 juin 91 ---------- Martin Boyer <mboyer@ireq-robot.hydro.qc.ca>
# Modifie : 14 avril 92 -------3- Martin Boyer <mboyer@ireq-robot.hydro.qc.ca>
#           Copyright (c) 1991 Hydro-Quebec
# 
# Historique: 
# 
# 14 avril 92 -------3- Martin Boyer <mboyer@ireq-robot.hydro.qc.ca>
# 	Commente un print de debug.
# 
# 28 janvier 92 -----2- Martin Boyer <mboyer@ireq-robot.hydro.qc.ca>
# 	Corrige pour lire les lignes continuees par des blancs.
# -----------------------------------------------------------------------------

# This simply recognizes the -t option and parses the mail message to
# dig out the recipients.  The recipients are then passed as command line
# arguments to sendmail.  This is a hack, but I'll be glad to get the bugs out
# if you document and send them to my attention.


#The sendmail program itself

$sendmail = '/usr/lib/sendmail';

while ($_ = $ARGV[0]) {
    shift;
    if (/^-t/) {
	$parse++;
    } else {
	@nargv = (@nargv, $_);
    }    
}

# printf("ARGS: %s\n", join(" ", @nargv));

sub cleanup {
    unlink $tmpname;
    exit(1);
}

if ($parse) {

    # Look for comma-separated destination addresses in the message

    $SIG{'INT'} = 'cleanup';
    $SIG{'QUIT'} = 'cleanup';
    $SIG{'TERM'} = 'cleanup';
    local($appending) = 0;
    $tmpname = "/tmp/sm-fix$$";
    open(TMP, ">$tmpname");

    while ( $line = <> ) {
	print TMP $line;
	chop ($line);
	
	# The end of header is marked by the first empty line.
	last if $line eq "";

	# Skip uninteresting lines
	if ($line !~ /^(To|Bcc|Cc|Fcc):\s+/io &&
	    !($appending && $line =~ /^\s+/io)) {
	    #print "Skipping $line\n";
	    $appending = 0;
	    next;
	}
	$appending = 1;

	# Remove Field names
	$line =~ s/^\S*\s+(.*)/\1/;
	# Remove "(User Name)" fields
	$line =~ s/\([^()]*\)//go;
	# Split into individual recipients
	split(/,+/, $line);
	# If an <address> field is present, use that
	foreach (@_) { s/.*\<([^<>]*)\>.*/$1/o; };
	@dest = (@dest, @_);
    }

    # Output the rest of the message.
    while (<>) {
	print TMP $_;
    }
    close TMP;

    # printf("Dest: %s\n", join(" ", @dest));
    $cmd = sprintf("$sendmail %s %s < $tmpname",
		   join(" ", @nargv), join(" ", @dest));
    # print $cmd, "\n";
    system $cmd;
    unlink $tmpname;

} else {

    # If the -t option isn't used, do nothing
    open(CMD, sprintf("| $sendmail %s", join(" ", @nargv)));
    while (<>) {
	print CMD $_;
    }
    close CMD;

}

exit 0;

--
Martin Boyer                            mboyer@ireq-robot.hydro.qc.ca
Institut de recherche d'Hydro-Quebec    mboyer@ireq-robot.uucp
Varennes, QC, Canada   J3X 1S1
+1 514 652-8412