I'm going to reply to a bunch of messages all at once.  I'm
attaching my first quick attempt at a configuration script; I've
called mutt-makeconfig, for lack of a better name.   It's very
brute force, but it works.  The config is very basic, enough to
get the bare minimum of personalized part of the process done
(ie, it sets realname, from, alternates, editor, folder,
mbox_type, print_command, and sendmail).  It's written in perl,
uses only standard (5.00505+) modules, and runs reasonably fast.
The options it takes are --muttrc (where it should write the
file, default /tmp/muttrc-$USER) and --color (a useless option to
make it purty).

And, just so everyone knows, I'm not really attached to the
script, they way it does things, the language it's written in, or
the choice of colors on the screen, so spare no flames. :)

Quoting Will Yardley <[EMAIL PROTECTED]> in 
<[EMAIL PROTECTED]>:
> regarding cvs space, i've never setup a cvs pserver before; i'm
> assuming this will be the easiest way to offer anonymous CVS
> access.  i doubt it's that hard to setup though.

Anonymous CVS access is not enough, because the folks working on
it will need write access; that means user accounts.  If we make
it a sourceforge project, then all the hard work is handled for
us, at least in that department.

Quoting Michael Maibaum <[EMAIL PROTECTED]> in 
<[EMAIL PROTECTED]>:
> That is OK for read access, dubious for write access(which
> should be by ssh probably), add a cvs module to the mutt.newbie
> project at sourceforge?

This was my thought, either attach ourselves to the mutt-newbie
project or start a new project on sourceforge.

Quoting Erika Pacholleck <[EMAIL PROTECTED]> in <[EMAIL PROTECTED]>:
> Take a language which you can expect to be present on minimal
> systems.  Otherwise you might end up in dependencies which are
> no advantage for mutt. One of the advantages of console progs
> is that they do not need hundreds of extra languages installed
> to get them going.

Yes.  Similarly:

Quoting John Buttery <[EMAIL PROTECTED]> in <[EMAIL PROTECTED]>:
> I agree with this logic; there's nothing that this shell script
> needs to do that can't be done with a Bourne shell script.
> That's the one interpreter you're always guaranteed to have.

I agree entirely.  sh is the most likely candidate, if we are
going for it to run absolutely everywhere (I'd say awk would be
the second, followed by perl).  The script I've written doesn't
too (too many) Perl-ish things and should be strightforward to
port to whatever languagewe decide to use, if that's what is
wanted.

(darren)

--
The Feynman Problem       1) Write down the problem.
Solving Algorithm         2) Think real hard.
                          3) Write down the answer.
#!/usr/bin/perl

# ----------------------------------------------------------------------
# $Id$
# ----------------------------------------------------------------------
# Inital version by darren chamberlain <[EMAIL PROTECTED]>
# ----------------------------------------------------------------------

use strict;
use vars qw| $VERSION |;

use Sys::Hostname;  # To determine the hostname
use Text::Wrap;

# ----------------------------------------------------------------------
# Set defaults and local (script-level) variables.
# ----------------------------------------------------------------------
$VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/;
my $Muttrc = "/tmp/muttrc-$ENV{USER}";
my $help_only = undef;

# Normally, doing colors this way is kinda dumb; ANSI::Term and friends
# were designed to do this, but I wanted to ensure that no external
# modules were needed here.  Besides, you have to explicitly ask for
# color, so by default nothing bad will happen.
my $color = undef;
my $red   = "";
my $blue  = "";
my $green = "";
my $norm  = "";

# $ENV{COLUMNS} is some sh magic.  COLUMNS is usually only defined when
# running under X, but we rely on it a little later, so we define
# it if it isn't already defined.  Note that this does not propogate
# outwards to the parent process, so we're OK here.
$Text::Wrap::columns = $ENV{"COLUMNS"} ||= 80;

# ----------------------------------------------------------------------
# Get command line options, using the standard Getopt::Long module.
# ----------------------------------------------------------------------
use Getopt::Long;
GetOptions(
    "muttrc=s" => \$Muttrc,
    "color!"   => \$color,
    "help!"    => \$help_only,
);

# Perhaps nocolor should be the default?
if (defined $color) {
    $red   = "";
    $blue  = "";
    $green = "";
    $norm  = "";
}

my @config = ();    # Lines that will become the config file
my %env = ();       # Elements that will become the values

# ======================================================================
# "main"
# ======================================================================
populate_from_environment(\%env);

# ----------------------------------------------------------------------
# This is the banner, our short introduction to mutt-makeconfig.
# ----------------------------------------------------------------------
(my $prog = $0) =~ s,.*/,,;
my $help = wrap("", "", "Welcome to $red$prog$norm. $red$prog$norm "
  . "is designed to help you generate a simple configuration file that "
  . "can be used for the Mutt MUA <${blue}http://www.mutt.org/${norm}>. "
  . "Configuration files generated by $red$prog$norm can (and should) be "
  . "used as a basis for more complex and interesting configurations; "
  . "see <${blue}http://www.mutt.org/links.html#config${norm}> for "
  . "examples of what can be done.\n"
  . "\n"
  . "$red$prog$norm attempts to auto-detect as much about your setup as "
  . "it can, and uses reasonable defaults otherwise, where reasonable is "
  . "defined as Mutt's own defaults.  Always keep in mind that $red$prog"
  . "$norm merely writes a configuration file, which can always be edited "
  . "by hand with an editor, like $env{'editor'}, to suit your needs.\n\n");

print $help;
exit(0) if $help_only;

# ----------------------------------------------------------------------
# Begin!
# ----------------------------------------------------------------------
my $answer;
$answer = prompt("realname",
                 "Enter your real name",
                 q|This variable specifies what "real" or "personal" |
               . q|name should be used when sending messages.|,
                 $env{"realname"});
push @config, qq|set realname="$answer"|;


# ----------------------------------------------------------------------
# from
# ----------------------------------------------------------------------
$answer = prompt("from",
                 "Enter your default email address",
                 "This is your default email address.  "
               . "It can be overridden using my_hdr (including "
               . "from sendhooks) and \$reverse_name.",
                 sprintf "%s@%s", $env{"username"}, $env{"hostname"});
push @config, qq|set from="$answer"|;


# ----------------------------------------------------------------------
# alternates
#   Ask about alternate email addresses (set alternates="")
# ----------------------------------------------------------------------
$answer = "foo";
my @alternates;
while (length $answer) {
    $answer = prompt("alternates",
                     "Enter another email address, (<enter> when done)",
                     "",
                     "");
    push @alternates, $answer if length $answer;
}
my $alts = join '|', map { s/\./\\./g; $_ } @alternates;
push @config, qq|set alternates="($alts)"| if length $alts;

# ----------------------------------------------------------------------
# folder
#   Where to put read mail by default (set folder=~/Mail)
# ----------------------------------------------------------------------
$answer = prompt("folder",
                 "Where should your mail folders be stored",
                 "Specifies the default location of your mailboxes.  "
               . "A `+' or `=' at the beginning of a pathname will be "
               . "expanded to the value of this variable.  Note that if "
               . "you change this variable from the default value you "
               . "need to make sure that the assignment occurs before you "
               . "use `+' or `=' for any other variables since expansion "
               . "takes place during the `set' command.",
                 "~/Mail"
          );
push @config, qq|set folder="$answer"|;

# ----------------------------------------------------------------------
# mbox
#   Where to put read mail (set mbox=~/mbox)
# ----------------------------------------------------------------------
$answer = prompt("mbox",
                 "Where should your read mail be stored",
                 "This specifies the folder into which read mail in "
               . "your ``\$spoolfile'' folder will be appended.",
                 "~/mbox");
push @config, qq|set mbox="$answer"|;

# ----------------------------------------------------------------------
# mbox_type
#   What is mailbox foramt (set mbox_type=mbox)
# ----------------------------------------------------------------------
$answer = prompt("mbox_type",
                 "What mbox type will you use",
                 "The default mailbox type used when creating new "
               . "folders. May be any of mbox, MMDF, MH and Maildir.",
                 "mbox");
push @config, qq|set mbox_type="$answer"|;


# ----------------------------------------------------------------------
# postpone
# ----------------------------------------------------------------------
$answer = prompt("postpone",
                 "Use postponed mailbox",
                 "Controls whether or not messages are saved in the "
               . "``\$postponed'' mailbox when you elect not to send "
               . "immediately.",
                 "ask-yes");
push @config, qq|set postpone="$answer"|;

# ----------------------------------------------------------------------
# postponed
#   Where is the postpones mailbox (set postponed=~/postponed)
# ----------------------------------------------------------------------
if ($answer eq 'yes' or $answer eq 'ask-yes' or $answer eq 'ask-no') {
    $answer = prompt("postponed",
                 "Where should postponed messages be saved",
                 "Mutt allows you to indefinitely ``postpone sending a "
               . "message'' which you are editing.  When you choose to "
               . "postpone a message, Mutt saves it in the mailbox "
               . "specified by this variable.  Also see the ``\$postpone'' "
               . "variable.",
                 "~/postponed");
    push @config, qq|set postponed="$answer"|;
}

# ----------------------------------------------------------------------
# record
#   Where/whether to save outgoing mail (set record="")
# ----------------------------------------------------------------------
$answer = prompt("record",
                 "Where should sent mail go",
                 "This specifies the file into which your outgoing "
               . "messages should be appended.  (This is meant as the "
               . "primary method for saving a copy of your messages, but "
               . "another way to do this is using the ``my_hdr'' command "
               . "to create a Bcc: field with your email address in it.)",
                 "");
push @config, qq|set record="$answer"| if length $answer;

# ----------------------------------------------------------------------
# print
# ----------------------------------------------------------------------
$answer = prompt("print",
                 "Confirmation before printing",
                 "Controls whether or not Mutt asks for confirmation "
               . "before printing. This is useful for people "
               . "who accidentally hit ``p'' often.",
                 "ask-no");
push @config, qq|set print="$answer"|;


# ----------------------------------------------------------------------
# print_command
#   What is your local print command (set print_command="")
# ----------------------------------------------------------------------
$answer = prompt("print_command",
                 "With what command will you print",
                 "This specifies the command pipe that should be used "
               . "to print messages.",
                 "lpr");
push @config, qq|set print_command="$answer"| if length $answer;

# ----------------------------------------------------------------------
# sendmail
#   What is your local sendmail command (set sendmail="")
# ----------------------------------------------------------------------
$answer = prompt("sendmail",
                 "What do you use to sendmail",
                 "Specifies the program and arguments used to deliver "
               . "mail sent by Mutt.  Mutt expects that the specified "
               . "program interprets additional arguments as recipient "
               . "addresses.",
                 "/usr/sbin/sendmail -oem -oi");
push @config, qq|set sendmail="$answer"|;

# ----------------------------------------------------------------------
# editor
# ----------------------------------------------------------------------

write_config($Muttrc, \@config);

exit(0);

# ======================================================================
# Subroutine declarations
# ======================================================================

# ----------------------------------------------------------------------
# populate_from_environment()
#   Pull as much information from the environment as possible.
# ----------------------------------------------------------------------
sub populate_from_environment {
    my $env = shift;

    # Get the user information
    my @pw = getpwuid($<);
    my @gecos = split /,\s*/, $pw[6];

    $env->{"username"}  = $pw[0];
    $env->{"realname"}  = $gecos[0];
    $env->{"hostname"}  = hostname();
    $env->{"mailspool"} = $ENV{"MAIL"};
    $env->{"editor"}    = $ENV{"VISUAL"} || $ENV{"EDITOR"} || "builtin";

    return $env;
}

# ----------------------------------------------------------------------
# write_config(filename, \@config_lines);
#   Write the new config file
# ----------------------------------------------------------------------
sub write_config {
    my ($Muttrc, $config) = @_;
    print "Writing configuration file $Muttrc\n";
    local *OUTDIR;

    open OUTDIR, ">$Muttrc" or die "Can't open $Muttrc for writing: $!";
    for my $config_line (@{$config}) {
        printf OUTDIR "%s\n", $config_line;
    }
    close OUTDIR or die "Can't close $Muttrc: $!";
}

# ----------------------------------------------------------------------
# prompt(directive, prompt, description, default);
#   Creates a nice text display, and provides a nice input method.
# ----------------------------------------------------------------------
sub prompt {
    my ($directive, $prompt, $desc, $default) = @_;
    my $description = wrap("", " "x14, "${red}Description${norm}:  $desc");
    my $answer = "";

    print "\n";
    print "${red}Setting Name${norm}: $directive\n";
    print "$description\n" if length $desc;
    print "$prompt";
    print " [$blue$default$norm]" if length $default;
    print ": ";

    chomp($answer = <STDIN>);
    $answer = $default unless length $answer;
    return $answer;
}

__END__

Things this script needs to be able to configure, either automatically
or through a conversational interface:

1.  determine basic things from the environment:
    username ($ENV{USER} || $ENV{LOGNAME} || ...)
    hostname (use Sys::Hostname)
    domainname
    mail spool directories ($ENV{MAIL})
    editor of choice ($ENV{VISUAL} || $ENV{EDITOR} || "builtin" => set editor)

    Is user a pine or elm user?  Offer contrib/{Pine,Tin}.rc keybindings

2. Ask basic questions about system/setup, including:
    Real name (set realname="")
    Default address (set from="")
    Ask about alternate email addresses (set alternates="")
    Where to put read mail by default (set folder=~/Mail)
    Where to put read mail (set mbox=~/mbox)
    What is mailbox foramt (set mbox_type=mbox)
    Where is the postpones mailbox (set postponed=~/postponed)
    Where/whether to save outgoing mail (set record="")
    What is your local print command (set print_command="")
    What is your local sendmail command (set sendmail="")

    How do you want your mailboxes sorted (set sort="")

    signature file (~/.signature)
    alias file (~/.mail_aliases)

3. POP, IMAP, PGP, SSL, etc



Reply via email to