1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
|
#! @im_path_perl@
################################################################
###
### imsetup: setup command for IM
###
### Copyright (C) 1997 Internet Message Group
###
### This Perl5 library conforms
### GNU GENERAL PUBLIC LICENSE Version 2.
###
###
### Author: Internet Message Group <img@mew.org>
### Created: May 9, 1997
### Revised: @im_revised@
###
my $VERSION = "imsetup @im_version@";
$Prog = 'imsetup';
##
## Require packages
##
use File::Copy;
use Sys::Hostname;
use IM::Config qw(init_opt read_opt help);
use IM::Util;
use IM::Address qw(extract_addr);
use integer;
use strict;
use vars qw($Prog $EXPLANATION @OptConfig $opt_noharm $opt_help);
##
## Environments
##
my $imdir = ".im";
my $config = "Config";
my $alias = "Aliases";
my $home = $ENV{'HOME'};
my $address = im_getlogin() . "\@" . &get_domain_name();
my $mail = "Mail";
my $news = "News";
my $usecl = "no";
my $nosync = "no";
my ($mhdir, $mhalias, $domain, $nntpservers);
$EXPLANATION = "
$Prog :: Setup command for IM series
$VERSION
Usage :: $Prog [options]
";
@OptConfig = (
'noharm;b;;' => "Do execute setup, show what will be performed.",
'help;b;;' => "Show this message.",
);
##
## Profile and option processing
##
init_opt(\@OptConfig);
read_opt(\@ARGV); # help?
help($EXPLANATION) && exit $EXIT_SUCCESS if $opt_help;
##
## Main
##
&read_conf();
&check_im_directory();
&make_conf_file();
©_alias_file();
sub get_domain_name () {
my $hostname = hostname();
unless ($hostname =~ /\./) {
my ($h) = gethostbyname($hostname);
$hostname = $h if ($h);
}
$hostname =~ s/^[^.]+\.//;
return $hostname;
}
sub read_conf () {
$home = &input_config("Where is your home directory?", $home);
&scan_mh_conf();
my $mymail = "$home/$mail";
my $mynews = "$home/$news";
my $qhome = quotemeta($home);
do {
do {
$mymail = &input_config("Where is your Mail directory?", $mymail);
} until (($mail = $mymail) =~ s!^$qhome/!!e
|| &input_confirm("Sure to use $mail which is not beneath "
. "your home directory?"));
} while (! &check_and_create_directory($mymail));
do {
do {
$mynews = &input_config("Where is your News directory?", $mynews);
} until (($news = $mynews) =~ s!^$qhome/!!e
|| &input_confirm("Sure to use $news which is not beneath "
. "your home directory?"));
} while (! &check_and_create_directory($mynews));
$address = &input_config("What is your E-mail address(es)?", $address);
$usecl = &input_config("Do you want to use value of Content-Length"
. " header for delimitation for local\nmail?"
. " (Answer yes if your OS supports Content-Length"
. " header like Solaris 2.x,\notherwise answer no.)"
, $usecl);
$nosync = &input_config("Does your system can detect write errors without"
. " fsync(2)? (You can answer yes,\n"
. "if your home directory is on local file system,"
. " otherwise answer no.)"
, $nosync);
print "\n";
}
sub input_config ($$) {
my ($msg, $default) = @_;
my $ret;
print "$msg [$default] ";
chomp($ret = <STDIN>);
$ret = $default if ($ret =~ /^\s*$/);
return $ret;
}
sub input_confirm($;$) {
my ($msg, $default) = @_;
my $ret;
$default = "yes" if $default eq "";
print "$msg [$default] ";
chomp($ret = <STDIN>);
$ret = $default if ($ret =~ /^\s*$/);
return $ret =~ m/^y/i;
}
sub scan_mh_conf () {
my $mh_profile = "$home/.mh_profile";
if ( -f $mh_profile ) {
open(MH_PROFILE, $mh_profile);
while(<MH_PROFILE>) {
chomp;
if (/^Path:\s*/i) {
$mhdir = $mail = $';
}
if (/^Aliasfile:\s*/i) {
$mhalias = $';
}
if (/^Alternate-Mailboxes:\s*/i) {
$address = $';
}
}
} else {
$mhdir = $mail;
$mhalias = 'aliases';
}
}
sub check_im_directory () {
if ( -x "$home/$imdir" ) {
print "$home/$imdir is already exist.\n";
} else {
if (!$opt_noharm) {
if (mkdir("$home/$imdir", 0700) == 0) {
die "Fail to create $home/$imdir directory: $!\n";
}
print "Directory $home/$imdir created.\n";
}
}
}
sub check_and_create_directory ($) {
my $dir = shift;
if ( ! -x $dir ) {
if (&input_confirm("$dir does not exist. Create it?")) {
print "Creating $dir directory.\n";
if (!$opt_noharm) {
if (mkdir("$dir", 0700) == 0) {
die "Fail to create $dir directory: $!\n";
}
print "Directory $dir created.\n";
}
return 1;
}
else {
return 0;
}
}
return 1;
}
sub copy_alias_file () {
my $im_alias = "$home/$imdir/$alias";
my $mh_alias = "$home/$mhdir/$mhalias";
if ( -f $mh_alias && ! -f $im_alias ) {
print "Copy $mh_alias to $im_alias.\n";
if (!$opt_noharm) {
copy($mh_alias, $im_alias);
}
}
}
sub make_conf_file () {
my $im_config = "$home/$imdir/$config";
if ( -f $im_config ) {
print "Backup $im_config to $im_config.bak.\n";
if (!$opt_noharm) {
rename ("$im_config", "$im_config.bak");
}
}
print "Setup $im_config.\n";
if (!$opt_noharm) {
my $a = extract_addr($address);
$a =~ /\@/;
$domain = $';
$nntpservers = $ENV{'NNTPSERVER'} || "localhost";
open(CONFIG, ">$im_config");
print CONFIG <<"---";
################################################################
###
### Sample ~/.im/Config
###
### Syntax::
### key=value
###
### * "key=value" is equivalent to "--key=value" style command option.
### * "key" must start at the beginning of the line.
### * "=" must follow after "key" without white spaces.
### * White spaces are allowed between "=" and "value".
### * ":" can be used instead of "=".
### * Characters after "#" are ignored.
###
### The following examples are all the same:
### key=value
### key= value
### key:value
### key: value
###
### \$variable will be expanded.
### '~' will be expanded.
###
##
## Individual information
##
Address=$address
FromDomain=$domain
ToDomain=$domain
#Name=Full Name # commentary name for my mail address
#AddrRegex=
#Org=The Mew Organization # for news posting
##
## Default global parameters
##
### Directories (relative to ~/)
MailDir=$mail
NewsDir=$news # for saved news
### Folders in \$MailDir
#InboxFolder=+inbox # default destination of imget
#DraftFolder=+draft
#TrashFolder=+trash # default destination of message removal in Mew
### Folder style in \$NewsDir (saved news articles)
#PreserveDot=off # off: /news/group/, on: /news.group/
### Mode for creation
#FolderMode=0700
#MsgMode=0600
### To keep state of IM commands (CurrentFolder, etc.)
#ContextFile=Context # relative to ~/.im/
##
## Default settings
##
## Mail address aliases
#AliasesFile=Aliases # relative to ~/.im/
## PetName: mail address aliases for displaying
#PetnameFile=Petnames # relative to ~/.im/
## Message-ID database
#MsgDBFile=msgiddb # location (relative to ~/.im/)
#MsgDBType=DB # type of database (DB, NDBM, SDBM)
## To call user defined subroutines (relative to ~/.im/)
#GetSbr=get.sbr # hooks for imget
#ScanSbr=scan.sbr # hooks for imget/imls
## Working folders
#Src=\$InboxFolder # default source of most commands
#Imrm.Src=\$TrashFolder # default source for message cleanups
## imget/imls specific
#ScanSbr=scan.sbr # hook for special processing (rel. to ~/.im/)
#Form=%+5n %m%d %-14A %-18S %b # default format for scanning
#AllowCRLF=no # saved messages may contain CRLF (DOS style)
#Width=80 # default width for scanning
#JisSafe=on # escape seq. of JIS char. should be managed
#Indent=2 # indent step for threading
## Servers
#Smtpservers=localhost # default server for SMTP
#EmgSmtpSvrs=12.34.56.78,localhost # SMTP server just for error return
#NntpServers=localhost # default server for NNTP
## imget specific
#GetSbr=get.sbr # hook for special processing (rel. to ~/.im/)
#Imget.Src=local # default source of imget (local mailbox)
#lock=flock # locking style of local mailbox
#rpath=append # conversion of UNIX From into Return-Path:
#PopHistory=pophist # to save last state (relative to ~/.im/)
#NntpHistory=newshist # to save last state (relative to ~/.im/)
#MBoxStyle=qmail # if folder style mbox of qmail is used
#Imget.Src=local:\${HOME}/MailDir# in case of qmail
#UseCL=$usecl # Use value of Content-Length header
#NoSync=$nosync # Do not need fsync(2) on writing file
#PopAccount=/APOP\@localhost # account info for POP access
#PopAccount=user/APOP\@host # account info with user name
#PopAccount=user/APOP\@host/110 # account info with user name and port number
#Keep=7 # preserve read messages on server
#ProtoKeep=UIDL # how to know which message is unread
# (UIDL, LAST, STATUS, MSGID)
#IgnorePostPet=yes # leave messages for PostPet on mbox (POP only)
#ImapAccount=/AUTH\@localhost # account info for IMAP access
#ImapAccount=user/AUTH\@host # account info with user name
#HttpProxy=proxy-server:8080 # proxy server for HTTP access
#NoProxy=http://.*my.domain/ # URL regex not to use Proxy server
#UsePwAgent=yes # use password agent
#PwAgentPort=6543 # Port to connect pwagent with TCP/IP
# (Insecure for multi-user system!)
# 0 to use UNIX domain socket (more secure)
# be careful on security if you wish to use PwFiles!
#UsePwFiles=yes # use password files
#PwFiles=password # password files (relative to ~/.im/)
## imput specific
#FccDir=\$MailDir # directory for FCC folders
#QueueDir=queue # directory for to store messages to be sent
#MsgIdDomain=\${HOST} # if you want to use FQDN of dispatching host
#ObeyMTAdomain=yes # do not append domainpart to addresses by imput
#NoMsgIdForNews=yes # do not insert Message-Id: when posting as news
#NewsGMTdate=yes # use GMT for Date: when posting as news
#noJPheader # do not encode ISO-2022-JP with RFC2047
#Defcode=EUC # default code in case no way to judge SJIS/EUCj
#JPconv=yes # convert SJIS/EUCj to ISO-2022-JP
#NoHdrFolding=yes # do not fold long header line when encoding
#HdrQEncoding=yes # use Q-encoding to encode ISO-2022-JP
#NameInComment=yes # yes: (Full Name) Addr, no: Full Name <Addr>
#Lines=3000 # unit to split a message to partial
#Annotate=yes # annotate on parent messages (MsgDB required)
# Common operational settings
#Help=no
#Quiet=no
#Noharm=no
#Verbose=no
#Debug=
#case mew
#FromDomain=mew.org
#case queue
#JustQueuing=yes
#Queuing=yes
#case news
#Assoc= +inbox=nntp:fj.mail.system.sendmail;\\
# +inbox=nntp:fj.mail
#Count=10
#case default
# -- global setting again --
---
}
}
### Local Variables:
### mode: perl
### End:
|