#!/bin/sh
#
if [ ! "$UID" = "0" ]; then
echo
echo "[$LOGNAME] You need to run this script as root."
echo "Try one of these to run it as root: # sudo mnsetup"
echo "                                    # su -c mnsetup"
echo
exit 
fi

if ! type -all dialog >/dev/null 2>&1 ; then
echo "Can't find 'dialog', i can't run without 'dialog' on the system."
exit 
fi

TMP=/tmp/1.$$

cat << EOF > $TMP
(1-8-2001)   

This is a shell script to setup mail & news on your system.  

It will setup "fetchmail" the mail client, "mutt" the mail reader, 
and "tin" the news reader.

You'll have to know a few things, your username, password, and email 
address.

You'll also need to know your service providers news server name,
and the mail protocol they use "pop3" etc. 

Read /usr/doc/guides/mail-news.txt.
EOF

dialog --title "READ" --yesno "`cat $TMP`" 19 74

if [ $? = 1 ]; then
rm -f $TMP
echo
exit
fi

MUTTRC() {
cat <<EOF
# This is a \$HOME/.muttrc file.
# The format of this file is one command per line.  Everything after a pound
# sign (#) is a comment, unless a backward slash (\) precedes it.
# man mutt     "Man pages"
# man muttrc

# User Defined Headers.
#
# You can put a From: and or a Reply-To: here.
#
# my_hdr From: Jerry Donut <jerry@foo.com>  <Examples>
# my_hdr Reply-To: jerry@foo.com   
# my_hdr Return-Receipt-To: jerry@foo.com

my_hdr From: $FULLNAME <$EMAIL>      
my_hdr Reply-To: $EMAIL
  
# You can put a Return-Receipt-To: if you want to be notified by sendmail
# when mail can't be delivered and why.

my_hdr Return-Receipt-To: $EMAIL 

set dsn_notify="failure,delay"   
set dsn_return="hdrs"            

# POP3 support.
# If you want mutt to connect to your service provider and get your
# pop3 mail, answer the questions below, then when you're in mutt & 
# connected, press the capital 'G' key.
$POP3

## The following options are only vaild if you have
## compiled in IMAP support.

# set imap_user=""
# set imap_pass=""
# set imap_checkinterval=""

# This is the default mailer for mutt.
set sendmail="/usr/sbin/sendmail -oi -oem -t"
#set sendmail_wait=-1

set folder="$HOME/Mail"			# Mail folder directory.
set spoolfile="$HOME/Mail/$USER"	# Mail folder.

set postponed=+postponed-mail           # Where postponed messages live.
set edit_hdrs                           # I want to edit the message headers.
set copy=ask-yes                        # Ask to keep copies of outgoing mail,
set record=+sent-mail                   # and it gets saved in sent-mail.
unset confirmappend
set autoedit
set sort=threads
set nobeep
set nomove
set mbox=+read-mail                     # Where to put mail you read. 

set read_inc=100              
set write_inc=0              

set mailcap_path=$HOME/.mailcap:/etc/mailcap

#set editor="emacs -nw"		# Editor to use when composing messages
#set editor="vi '+/^$'"
#set editor="vim '+/^$'"
#set editor="elvis '+/^$'"
#set editor="pico +8"
#set editor="nano +8"
#set editor="vfte -mSH -l8"
set editor="mcedit +8"
#set editor=builtin

#set visual="mcedit +8"         # Editor invoked by ~v in the builtin editor
#set visual="vi '+/^$'"

set quote_regexp="^( {0,4}[>|:]| {0,4}[a-z0-9]+[>|]+)+"

# Ignore all headers
ignore *

# Then un-ignore the ones I want to see
unignore From:
unignore Subject:
unignore To:
unignore Reply-To:
unignore CC:
unignore BCC:
unignore Date:
unignore Organization:
unignore Newsgroups:
unignore X-Mailer:

# Now order the visable header lines
hdr_order From: Subject: To: Reply-To: CC: BCC: Date: Organization: Newsgroups: X-Mailer:

# Use the keys Ctrl b to connect to a URL using lynx while in mutt.
# If you see a http:// or ftp:// URL in a piece of email press Ctrl b.

macro index \cb |urlview\n
macro pager \cb |urlview\n	

# Default color definitions
color hdrdefault black        cyan
color quoted     red          white
color signature  brightblack  white
color indicator  brightwhite  red
color attachment black        green
color error      red          white
color message    blue         white
color search     brightwhite  magenta
color status     brightyellow blue
color tree       red          white
color normal     blue         white
color tilde      green        white
color bold       brightyellow white
color underline  magenta      white
color markers    red          white

# Colour definitions when on a mono screen
mono bold      bold
mono underline underline
mono indicator reverse

# Colours for items in the reader
color header brightwhite cyan "^(From|Subject):"
mono header bold              "^(From|Subject):"

# Colours for items in the index
color index brightblue  white ~N
color index red         white ~F
color index black       green ~T
color index brightwhite black ~D
mono  index bold              ~N
mono  index bold              ~F
mono  index bold              ~T
mono  index bold              ~D

# Highlights inside the body of a message.

# URLs
color body brightblue  white "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
color body brightblue  white "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"
mono  body bold              "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
mono  body bold              "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"

# email addresses
color body brightblue  white "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+"
mono  body bold              "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+"

# Various smilies and the like
color body brightgreen white "<[Gg]>"               # <g>
color body brightgreen white "<[Bb][Gg]>"           # <bg>
color body brightgreen white " [;:]-*[)>(<|]"       # :-) etc...

# Last, but not least, get mutt to display it's version on startup.
push V
EOF
}

TINRC() {
cat <<EOF
# tin configuration file V1.2
# This file was automatically saved by tin 1.5.7 20000929 ("Dust")
#
# Do not edit while tin is running, since all your changes to this file
# will be overwritten when you leave tin.
#
############################################################################

# Directory where articles/threads are saved
default_savedir=$HOME/News

# If ON articles/threads with Archive-name: in mail header will
# be automatically saved with the Archive-name & part/patch no.
auto_save=OFF

# If ON mark articles that are saved as read
mark_saved_read=ON

# Type of post processing to perform after saving articles.
# 0=(none) 1=(unshar) 2=(uudecode)
post_process_type=0

# If set, post processed files will be opened in a viewer
post_process_view=ON

# If ON only save/print/pipe/mail unread articles (tagged articles excepted)
process_only_unread=OFF

# If ON show empty Followup-To header when editing an article
prompt_followupto=OFF

# If ON confirm certain commands with y/n before executing
confirm_action=ON

# If ON confirm with y/n before quitting ('Q' never asks)
confirm_to_quit=ON

# If ON automatically reconnect to NNTP server if the connection is broken
auto_reconnect=OFF

# If ON use -> otherwise highlighted bar for selection
draw_arrow=OFF

# If ON use inverse video for page headers at different levels
inverse_okay=ON

# If ON put cursor at first unread art in group otherwise last art
pos_first_unread=ON

# If ON show only new/unread articles otherwise show all.
show_only_unread=ON

# If ON show only subscribed to groups that contain unread articles.
show_only_unread_groups=OFF

# 0=(Only kill unread articles)
# 1=(Kill all articles and show in threads marked with K)
# 2=(Kill all articles and never show them).
kill_level=0

# If ON the TAB command will goto next unread article at article viewer level
tab_goto_next_unread=ON

# If ON the SPACE command will goto next unread article at article viewer
# level when the end of the article is reached (rn-style pager)
space_goto_next_unread=OFF

# If ON the PGDN or DOWN command will goto next article when pressed
# at end of message
pgdn_goto_next=ON

# If ON a TAB command will be automatically done after the X command
tab_after_X_selection=OFF

# If ON scroll full page of groups/articles otherwise half a page
full_page_scroll=ON

# If ON show the last line of the previous page as first line of next page
show_last_line_prev_page=OFF

# If ON ask user if read groups should all be marked read
catchup_read_groups=OFF

# If ON catchup group/thread when leaving with the left arrow key.
group_catchup_on_exit=ON
thread_catchup_on_exit=ON

# Thread articles on 0=(nothing) 1=(Subject) 2=(References) 3=(Both).
thread_articles=3

# If ON show group description text after newsgroup name at
# group selection level
show_description=ON

# Part of from field to display 0) none 1) address 2) full name 3) both
show_author=2

# Which news headers you wish to see. If you want to see _all_ the headers,
# place an '*' as this value. This is the only way a wildcard can be used.
# If you enter 'X-' as the value, you will see all headers beginning with
# 'X-' (like X-Alan or X-Pape). You can list more than one by delimiting with
# spaces. Not defining anything turns off this option.
news_headers_to_display=Newsgroups Followup-To Summary Keywords 

# Same as 'news_headers_to_display' except it denotes the opposite.
# An example of using both options might be if you thought X- headers were
# A Good Thing(tm), but thought Alan and Pape were miscreants...well then you
# would do something like this:
# news_headers_to_display=X-
# news_headers_to_not_display=X-Alan X-Pape
# Not defining anything turns off this option.
news_headers_to_not_display=

# If ON use print current subject or newsgroup description in the last line
info_in_last_line=OFF

# Sort articles by 0=(nothing) 1=(Subject descend) 2=(Subject ascend)
# 3=(From descend) 4=(From ascend) 5=(Date descend) 6=(Date ascend)
# 7=(Score descend) 8=(Score ascend).
sort_article_type=6

# (-m) directory where articles/threads are saved in mailbox format
default_maildir=$HOME/Mail

# If ON save mail to a MMDF style mailbox (default is normal mbox format)
save_to_mmdf_mailbox=OFF

# If ON, the realname in the X-Comment-To header is displayed in the
# upper-right corner. You can use news_headers_to_display=X-Comment-To
# instead of this
show_xcommentto=OFF

# If ON print all of article header otherwise just the important lines
print_header=OFF

# Print program with parameters used to print articles/threads
default_printer=/usr/bin/lpr

# If ON articles/threads will be saved in batch mode when save -S
# or mail (-M/-N) is specified on the command line
batch_save=ON

# If ON editor will be started with cursor offset into the file
# otherwise the cursor will be positioned at the first line
start_editor_offset=ON

# Format of editor line including parameters
# %E Editor  %F Filename  %N Linenumber
default_editor_format=%E +%N %F

# Format of mailer line including parameters
# %M Mailer  %S Subject  %T To  %F Filename  %U User (AmigaDOS)
# ie. to use elm as your mailer:    elm -s "%S" "%T" < %F
# ie. elm interactive          :    elm -i %F -s "%S" "%T"
default_mailer_format=%M -t < %F

# Interactive mailreader: if ON mailreader will be invoked earlier for
# reply so you can use more of its features (eg. MIME, pgp, ...)
# this option has to suit default_mailer_format
use_mailreader_i=OFF

# Show number of lines of first unread article in thread listing (ON/OFF)
show_lines=ON

# Show score of article/thread in listing (ON/OFF)
show_score=OFF

# If ON remove ~/.article after posting.
unlink_article=ON

# If ON keep all failed postings in ~/dead.articles
keep_dead_articles=ON

# If ON keep all postings in ~/Mail/file (see below)
keep_posted_articles=ON

# Filename where to keep all postings (default posted)
keep_posted_articles_file=posted

# If ON add posted articles to filter for highlighting follow-ups
add_posted_to_filter=ON

# Signature path (random sigs)/file to be used when posting/replying
# default_sigfile=file       appends file as signature
# default_sigfile=!command   executes external command to generate a signature
# default_sigfile=--none     don't append a signature
default_sigfile=$HOME/.Sig

# If ON prepend the signature with dashes '\n-- \n'
sigdashes=ON

# If ON add signature to reposted articles
signature_repost=ON

# A comma-delimited list of address-parts you want to be warned
# about when trying to reply by email.
spamtrap_warning_addresses=

# If ON include advertising User-Agent: header
advertising=ON

# Time interval in seconds between rereading the active file (0=never)
reread_active_file_secs=1200

# Characters used in quoting to followups and replys.
# '_' is replaced by ' ', %s, %S are replaced by author's initials.
quote_chars=>_

# If ON quote empty lines, too
quote_empty_lines=ON

# A regular expression that tin will use to decide which lines are
# quoted when viewing articles. Quoted lines are shown in col_quote.
# If you leave this blank, tin will use a builtin default.
quote_regex=^\s{0,3}(?:[\]{}>|:)]|\w{1,3}[>|])(?!-)

# A regular expression that tin will use to decide which lines are
# quoted twice. Twice quoted lines are shown in col_quote2.
# If you leave this blank, tin will use a builtin default.
quote_regex2=^\s{0,3}(?:(?:[\]{}>|:)]|\w{1,3}[>|])\s*){2}(?!-[})>])

# A regular expression that tin will use to decide which lines are
# quoted >=3 times. >=3 times quoted lines are shown in col_quote3.
# If you leave this blank, tin will use a builtin default.
quote_regex3=^\s{0,3}(?:(?:[\]{}>|:)]|\w{1,3}[>|])\s*){3}

# A regular expression that tin will use to find Subject prefixes
# which will be removed before showing the header.
strip_re_regex=(?:R[eE](?:\^\d+|\[\d\])?|A[wW]|Odp|Sv):\s

# A regular expression that tin will use to find Subject suffixes
# which will be removed when replying or posting followup.
strip_was_regex=.\((?:[Ww]a[rs]|[Bb]y[l]o):.*\)\s*$

# If ON quote signatures, too
quote_signatures=OFF

# If OFF don't show signatures when displaying articles
show_signatures=ON

# If ON uuencoded data will be condensed to a single tag line showing
# size and filename, similar to how MIME attachments are displayed
hide_uue=OFF

# Format of quote line when mailing/posting/following-up an article
# %A Address    %D Date   %F Addr+Name   %G Groupname   %M Message-Id
# %N Full Name  %C First Name
news_quote_format=%F wrote:
mail_quote_format=In article %M you wrote:
xpost_quote_format=In %G %F wrote:

# If ON automatically put your name in the Cc: field when mailing an article
auto_cc=OFF

# If ON automatically put your name in the Bcc: field when mailing an article
auto_bcc=OFF

# Character used to show that an art was deleted (default 'D')
# _ is turned into ' '
art_marked_deleted=D

# Character used to show that an art is in a range (default '#')
# _ is turned into ' '
art_marked_inrange=#

# Character used to show that an art will return (default '-')
# _ is turned into ' '
art_marked_return=-

# Character used to show that an art was auto-selected (default '*')
# _ is turned into ' '
art_marked_selected=*

# Character used to show that an art is recent (default 'o')
# _ is turned into ' '
art_marked_recent=o

# Character used to show that an art is unread (default '+')
# _ is turned into ' '
art_marked_unread=+

# Character used to show that an art was read (default ' ')
# _ is turned into ' '
art_marked_read=_

# Character used to show that an art was killed (default 'K')
# kill_level must be set accordingly, _ is turned into ' '
art_marked_killed=K

# Character used to show that an art was selected before read (default ':')
# kill_level must be set accordingly, _ is turned into ' '
art_marked_read_selected=:

# If ON a screen redraw will always be done after certain external commands
force_screen_redraw=OFF

# If ON use the builtin mini inews for posting via NNTP
# otherwise use an external inews program
use_builtin_inews=ON

# If ON automatically list thread when entering it using right arrow key.
auto_list_thread=ON

# If ON enable mouse key support on xterm terminals
use_mouse=OFF

# If ON strip blanks from end of lines to speedup display on slow terminals
strip_blanks=ON

# Maximum length of the names of newsgroups displayed
groupname_max_length=32

# If ON show a mini menu of useful commands at each level
# and posting etiquette after composing an article
beginner_level=ON

# Num of days a short term filter will be active
default_filter_days=28

# If ON, create local copies of NNTP overview files.
cache_overview_files=OFF

# If ON limit the number of articles to get
use_getart_limit=OFF

# Number of articles to get (0=no limit), if negative sets maximum number
# of already read articles to be read before first unread one
getart_limit=0

# Number of days in which article is considered recent, (0=OFF)
recent_time=2

# If ON using ANSI-color
use_color=OFF

# For color-adjust use the following numbers
#  0-black       1-red         2-green        3-brown
#  4-blue        5-pink        6-cyan         7-white
# These are *only* for foreground:
#  8-gray        9-lightred   10-lightgreen  11-yellow
# 12-lightblue  13-lightpink  14-lightcyan   15-lightwhite
# A '-1' is interpreted as default (foreground normally is white, and
# background black)

# Standard foreground color
col_normal=7

# Standard-Background-Color
col_back=0

# Color of background for inverse text
col_invers_bg=4

# Color of foreground for inverse text
col_invers_fg=7

# Color of text-lines
col_text=7

# Color of mini help menu
col_minihelp=3

# Color of help pages
col_help=7

# Color of messages in last line
col_message=6

# Color of quote-lines
col_quote=2

# Color of twice quoted lines
col_quote2=3

# Color of >=3 times quoted lines
col_quote3=4

# Color of header-lines
col_head=2

# Color of actual news header fields
col_newsheaders=9

# Color of article subject
col_subject=6

# Color of response counter
col_response=2

# Color of sender (From:)
col_from=2

# Color of Help/Mail-Sign
col_title=4

# Color of signature
col_signature=4

# Enable word highlighting?
word_highlight=ON

# Should the leading and ending stars and dashes also be displayed,
# even when they are highlighting marks?
# 0 - no    1 - yes, display mark    2 - print a space instead
# 3 - print a space, but only in signatures
word_h_display_marks=2

# Color of word highlighting. There are two possibilities for
# in Articles: *stars* and _underdashes_
col_markstar=11
col_markdash=13

# User's mail address, if not username@host
mail_address=$FULLNAME <$EMAIL>

# Charset supported locally which is also used for MIME header and
# Content-Type header unless news and mail need to be encoded in other
# charsets as in case of EUC-KR for Korean which needs to be converted to
# ISO-2022-KR in mail message.
# If not set, the value of the environment variable MM_CHARSET is used.
# Set to US-ASCII or compile time default if neither of them is defined.
# If MIME_STRICT_CHARSET is defined at compile-time, charset other than
# mm_charset is considered not displayable and represented as '?'.
mm_charset=ISO-8859-1

# MIME encoding (8bit, base64, quoted-printable, 7bit) of the body
# for mails and posts, if necessary. QP is efficient for most European
# character sets (ISO-8859-X) with small fraction of non-US-ASCII chars,
# while Base64 is more efficient for most 8bit East Asian,Greek,and Russian
# charsets with a lot of 8bit characters.
# For EUC-KR, 7bit encoding specifies that EUC charsets be converted
# to corresponding ISO-2022-KR. The same may be true of EUC-JP/CN.
# Korean users should set post_mime_encoding to 8bit and mail_mime_encoding
# to 7bit. With mm_charset to EUC-KR, post_mime_encoding set to 7bit does
# NOT lead to conversion of EUC-KR into ISO-2022-KR in news-postings since
# it's never meant to be used for Usenet news. Japanese always use
# ISO-2022-JP for both news and mail. Automatic conversion of EUC-JP and
# other 8bit Japanese encodings into ISO-2022-JP (even if 7bit is chosen)
# is NOT yet implemented. (it may not be necessary at all as Japanese
# terminal emulators and editors appear to have native support of
# ISO-2022-JP). In case of Chinese, the situation seems to be more
# complicated (different newsgroups and hierarchies for Chinese use different
# MIME charsets and encodings) and no special handling is yet implemented.
# Summing up 7bit does NOT have any effect on MIME charset other than EUC-KR
post_mime_encoding=8bit
mail_mime_encoding=7bit

# If ON, 8bit characters in news headers are NOT encoded.
# default is OFF. Thus 8bit characters are encoded by default.
# 8bit chars in header are encoded regardless of the value of this
# parameter unless post_mime_encoding is 8bit as well.
post_8bit_header=OFF

# If ON, 8bit characters in mail headers are NOT encoded.
# default is OFF. Thus 8bit characters are encoded by default.
# 8bit chars in headers are encoded regardless of the value of this parameter
# unless mail_mime_encoding is 8bit as well. Note that RFC 1552/1651/1652
# prohibit 8bit characters in mail headers so that you are advised NOT to
# turn it ON unless you have some compelling reason.
mail_8bit_header=OFF

# If ON metamail can/will be used to display MIME articles
use_metamail=ON

# If ON tin will ask before using metamail to display MIME messages
# this only happens if use_metamail is switched ON
ask_for_metamail=ON

# If ON strip multipart/alternative messages automatically
alternative_handling=ON

# If ON strip unsubscribed groups from newsrc
strip_newsrc=OFF

# What to do with bogus groups in newsrc file
# 0=(Keep) 1=(Remove) 2=(Highlight with D on selection screen).
strip_bogus=2

# Wildcard matching 0=(wildmat) 1=(regex)
wildcard=0

# Defaults for quick (1 key) kill & auto-selection filters
# header=NUM  0,1=Subject: 2,3=From: 4=Message-Id: & full References: line
#             5=Message-Id: & last References: entry only
#             6=Message-Id: entry only 7=Lines:
# global=ON/OFF  ON=apply to all groups OFF=apply to current group
# case=ON/OFF    ON=filter case sensitive OFF=ignore case
# expire=ON/OFF  ON=limit to default_filter_days OFF=don't ever expire
default_filter_kill_header=0
default_filter_kill_global=ON
default_filter_kill_case=ON
default_filter_kill_expire=OFF
default_filter_select_header=0
default_filter_select_global=ON
default_filter_select_case=ON
default_filter_select_expire=OFF

# Default action/prompt strings
default_save_mode=a
default_author_search=
default_goto_group=
default_config_search=
default_group_search=
default_subject_search=
default_art_search=
default_repost_group=
default_mail_address=
default_move_group=0
default_pipe_command=
default_post_newsgroups=
default_post_subject=
default_range_group=1-.
default_range_select=1-.
default_range_thread=0-.
default_regex_pattern=
default_save_file=savefile.tin
default_select_pattern=
default_shell_command=

# Host & time info used for detecting new groups (don't touch)
newnews=local 972377032 (2000-10-24 08:43:52 UTC)
EOF
}

NAMES="$LOGNAME root jerry mary"
[ "$LOGNAME" = "root" ] && NAMES="root jerry larry mary"

while [ 0 ]
do
cat << EOF > $TMP 
What's the name of the user on this system, you want 
to setup for mail and news?

Examples: $NAMES
EOF

dialog --title "Username" --inputbox "`cat $TMP`" 11 60 2> $TMP

if [ $? = 1 ]; then
rm -f $TMP
echo
exit
fi

USER=`cat $TMP`
HOME="/home/$USER"

if [ -z "$USER" ]; then
continue
elif [ "$USER" = "root" ]; then
mkdir -p /root
HOME=/root
break
elif [ ! -d $HOME ]; then 
cat << EOF > $TMP
Home directory $HOME not found!
EOF
dialog --title "Not Found!" --msgbox "`cat $TMP`" 6 60 2> $TMP
continue
else
break
fi
done

cat << EOF > $TMP 
What mail protocol does your service provider use?

Choices: 
apop auto etrn imap imap-crammd5 imap-gss imap-k4 imap-login 
kpop pop2 pop3 rpop sdps 

Example: pop3
If not sure put: auto
EOF

dialog --title "Mail Protocol" --inputbox "`cat $TMP`" 15 68 2> $TMP

if [ $? = 1 ]; then
rm -f $TMP
echo
exit
fi

PROTO=`cat $TMP`

cat << EOF > $TMP 
What is your username or login name?

Example: jerry
EOF

dialog --title "Username" --inputbox "`cat $TMP`" 10 42 2> $TMP

if [ $? = 1 ]; then
rm -f $TMP
echo
exit
fi

USR=`cat $TMP`

cat << EOF > $TMP 
What is your password?

Example: X1fG4opa
EOF

dialog --title "Password" --inputbox "`cat $TMP`" 10 42 2> $TMP

if [ $? = 1 ]; then
rm -f $TMP
echo
exit
fi

PASS=`cat $TMP`

cat << EOF > $TMP 
What is your email address?

Example: $USR@your.isp.com	
EOF

dialog --title "Email Address" --inputbox "`cat $TMP`" 10 55 2> $TMP

if [ $? = 1 ]; then
rm -f $TMP
echo
exit
fi

EMAIL=`cat $TMP`

cat << EOF > $TMP 
What's your full name, first and last?

Example: Jerry Donut 	
EOF

dialog --title "Full Name" --inputbox "`cat $TMP`" 10 45 2> $TMP

if [ $? = 1 ]; then
rm -f $TMP
echo
exit
fi

FULLNAME=`cat $TMP`

cat << EOF > $TMP
What's the name of your isp's mail server?

Example: mail.ispname.com or pop3.ispname.com
EOF
dialog --title "MAIL SERVER NAME" --inputbox "`cat $TMP`" 0 0 2> $TMP
if [ $? = 1 ]; then
rm -f $TMP
echo
exit
fi
SITE=`cat $TMP`
cat << EOF > $TMP 
What's the name of your news server?

Example: news.something.com	
EOF

dialog --title "News Server" --inputbox "`cat $TMP`" 10 45 2> $TMP

if [ $? = 1 ]; then
rm -f $TMP
echo
exit
fi

NEWSSERVER=`cat $TMP`

cat << EOF > $TMP 
OK! i have the info, should i continue and setup the files? 
EOF

dialog --title "Continue?" --yesno "`cat $TMP`" 6 65 2> $TMP

if [ $? = 1 ]; then
rm -f $TMP
echo
exit
fi

echo 'poll "'$SITE'"' > $HOME/.fetchmailrc
echo "protocol $PROTO" >> $HOME/.fetchmailrc
echo 'username "'$USR'"' >> $HOME/.fetchmailrc
echo 'password "'$PASS'"' >> $HOME/.fetchmailrc
echo 'mda "'/usr/bin/procmail -d %s'"' >> $HOME/.fetchmailrc

echo >> $HOME/.fetchmailrc
chmod 600 $HOME/.fetchmailrc
chown $USER".users" $HOME/.fetchmailrc
echo "Created $HOME/.fetchmailrc file:" > $TMP

mkdir -p $HOME/Mail
chmod 700 $HOME/Mail
chown $USER".users" $HOME/Mail

touch $HOME/Mail/$USER 2>/dev/null
echo "Created $HOME/Mail/$USER file:" >> $TMP

chmod 600 $HOME/Mail/$USER 2>/dev/null
chown $USER".users" $HOME/Mail/$USER 2>/dev/null

POP3="
#set pop_last		# Only read last unread mail.
#set pop_delete		# Delete mail after retrieving it.
#set pop_host=\"\"	# Your service providers mail server.
#set pop_user=\"\"	# Your username. 
#set pop_pass=\"\"	# Your password."

if [ "$PROTO" = "pop3" ]; then 
if `mutt -v 2>/dev/null | grep -q "+USE_POP"` ; then
POP3="
set pop_last		# Only read last unread mail.
set pop_delete		# Delete mail after retrieving it.
set pop_host=\"$SITE\"	# Your service providers mail server.
set pop_user=\"$USR\"	# Your username. 
set pop_pass=\"$PASS\"	# Your password."
fi
fi

MUTTRC > $HOME/.muttrc
chmod 600 $HOME/.muttrc
chown $USER".users" $HOME/.muttrc
echo "Created $HOME/.muttrc file:" >> $TMP

if `grep -q "mail_address=" $HOME/.tin/tinrc 2>/dev/null` ; then
cat $HOME/.tin/tinrc | sed "s/^.*mail_address=.*/mail_address=$FULLNAME <$EMAIL>/g" > $HOME/.tin/tinrc.new
mv $HOME/.tin/tinrc.new $HOME/.tin/tinrc
chmod 600 $HOME/.tin/tinrc
chown $USER".users" $HOME/.tin/tinrc
chown $USER".users" $HOME/.tin
echo "Put name & email address in $HOME/.tin/tinrc file:" >> $TMP
echo "mail_address=$FULLNAME <$EMAIL>" >> $TMP 
else
mkdir -p $HOME/.tin
chmod 700 $HOME/.tin
TINRC > $HOME/.tin/tinrc
chmod 600 $HOME/.tin/tinrc
chown $USER".users" $HOME/.tin/tinrc
chown $USER".users" $HOME/.tin
echo "Created $HOME/.tin/tinrc file with name & email address:" >> $TMP 
echo "mail_address=$FULLNAME <$EMAIL>" >> $TMP
fi

if [ ! -z $NEWSSERVER ]; then
if ! grep -q "^export NNTPSERVER=$NEWSSERVER" $HOME/.bash_login 2>/dev/null ; then
if grep -q "NNTPSERVER=" $HOME/.bash_login 2>/dev/null ; then
cat $HOME/.bash_login | sed "/^.*NNTPSERVER=.*/d" > $HOME/.bash_login.new
mv $HOME/.bash_login.new $HOME/.bash_login
echo "export NNTPSERVER=$NEWSSERVER" >> $HOME/.bash_login
else
echo "export NNTPSERVER=$NEWSSERVER" >> $HOME/.bash_login
fi
chmod 600 $HOME/.bash_login
chown $USER".users" $HOME/.bash_login
echo "Put news server in $HOME/.bash_login file:" >> $TMP
echo "export NNTPSERVER=$NEWSSERVER" >> $TMP
echo >> $TMP
if [ "$LOGNAME" = "$USER" ]; then
echo "You can do this after you exit this script!" >> $TMP
echo "# . $HOME/.bash_login" >> $TMP
fi
fi
fi

echo >> $TMP
echo "!!! Read /usr/doc/guides/mail-news.txt. !!!" >> $TMP
cat $TMP >> $TMP 2>/dev/null

dialog --title "Done!" --textbox "$TMP" 16 76
rm -f $TMP /tmp/sed.tmp
echo
