2 # Prints the user's email address, with confirmation from the user.
4 # Copyright (C) 2001-2003 Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # Prerequisites for using @libdir@ and @localedir@.
22 exec_prefix
="@exec_prefix@"
24 # Set variables libdir, localedir.
26 localedir
="@localedir@"
28 # Support for relocatability.
29 if test "@RELOCATABLE@" = yes; then
30 orig_installdir
="$libdir"/gettext # see Makefile.am's install rule
31 # Determine curr_installdir without caring for symlinked callers.
32 curr_installdir
=`echo "$0" | sed -e 's,/[^/]*$,,'`
33 curr_installdir
=`cd "$curr_installdir" && pwd`
34 # Compute the original/current installation prefixes by stripping the
35 # trailing directories off the original/current installation directories.
37 orig_last
=`echo "$orig_installdir" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'`
38 curr_last
=`echo "$curr_installdir" | sed -n -e 's,^.*/\([^/]*\)$,\1,p'`
39 if test -z "$orig_last" ||
test -z "$curr_last"; then
42 if test "$orig_last" != "$curr_last"; then
45 orig_installdir
=`echo "$orig_installdir" | sed -e 's,/[^/]*$,,'`
46 curr_installdir
=`echo "$curr_installdir" | sed -e 's,/[^/]*$,,'`
48 # Now relocate the directory variables that we use.
49 libdir
=`echo "$libdir/" | sed -e "s%^${orig_installdir}/%${curr_installdir}/%" | sed -e 's,/$,,'`
50 localedir
=`echo "$localedir/" | sed -e "s%^${orig_installdir}/%${curr_installdir}/%" | sed -e 's,/$,,'`
53 # Internationalization.
55 TEXTDOMAIN
=gettext-tools
57 TEXTDOMAINDIR
="$localedir"
60 # Redirect fileno 3 to interactive I/O.
68 # Find the user name on the local machine.
69 user
=`id -u -n 2>/dev/null`
70 if test -z "$user"; then
72 if test -z "$user"; then
74 if test -z "$user"; then
81 # hostname on some systems (SVR3.2, old Linux) returns a bogus exit status,
82 # so uname gets run too, so we keep only the first line of output.
83 #host=`(hostname || uname -n) 2>/dev/null | sed 1q`
84 host=`"$libdir"/gettext/hostname --short 2>/dev/null | sed 1q`
87 hostfqdn
=`"$libdir"/gettext/hostname --fqdn 2>/dev/null | sed 1q`
89 # Find a list of email addresses from various mailer configuration files.
90 # All mailers use configuration files under $HOME. We handle them in a
91 # last-modified - first-priority order.
95 # ----------------------- BEGIN MAILER SPECIFIC CODE -----------------------
98 files
="$files .mozilla/*/prefs.js"
100 # Netscape 4 addresses
101 files
="$files .netscape/liprefs.js .netscape/preferences.js"
103 # Netscape 3 addresses
104 files
="$files .netscape/preferences"
106 # Emacs/XEmacs rmail, Emacs/XEmacs gnus, XEmacs vm addresses
107 # XEmacs mew addresses
108 files
="$files .emacs .emacs.el"
111 files
="$files .kde2/share/config/emaildefaults"
113 # KDE kmail addresses
114 files
="$files .kde2/share/config/kmailrc"
116 # GNOME evolution addresses
117 files
="$files evolution/config.xmldb"
119 # GNOME balsa addresses
120 files
="$files .gnome/balsa"
122 # StarOffice and OpenOffice addresses
123 sed_dos2unix
='s/\r$//'
124 sed_soffice51
='s,StarOffice 5\.1=\(.*\)$,\1/sofficerc,p'
125 sed_soffice52
='s,StarOffice 5\.2=\(.*\)$,\1/user/sofficerc,p'
126 sed_ooffice
='s,^OpenOffice[^=]*=\(.*\)$,\1/user/config/registry/instance/org/openoffice/UserProfile.xml,p'
127 files
="$files Office51/sofficerc Office52/user/sofficerc "`sed -n -e "$sed_dos2unix" -e "$sed_soffice51" -e "$sed_soffice52" -e "$sed_ooffice" .sversionrc 2>/dev/null | sed -e 's,^file://*,/,'`
130 files
="$files .muttrc"
133 files
="$files .pinerc"
136 files
="$files .xfmail/.xfmailrc"
139 files
="$files .ratatosk/ratatoskrc"
141 # ----------------------- END MAILER SPECIFIC CODE -----------------------
143 # Expand wildcards and remove nonexistent files from the list.
145 for file in $files; do
146 if test -r "$file" && test ! -d "$file"; then
147 nfiles
="$nfiles $file"
154 if test -n "$files"; then
156 for file in `ls -t $files`; do
160 # ----------------------- BEGIN MAILER SPECIFIC CODE -----------------------
164 addresses
="$addresses "`grep -h '^user_pref("mail\.identity\..*\.useremail", ".*");$' $file 2>/dev/null | sed -e 's/^user_pref("mail\.identity\..*\.useremail", "\(.*\)");$/\1/'`
167 # Netscape 4 addresses
168 .netscape
/liprefs.js | .netscape
/preferences.js
)
169 addresses
="$addresses "`grep -h '^user_pref("mail\.identity\.useremail", ".*");$' $file 2>/dev/null | sed -e 's/^user_pref("mail\.identity\.useremail", "\(.*\)");$/\1/'`
172 # Netscape 3 addresses
173 .netscape
/preferences
)
174 addresses
="$addresses "`grep -h '^EMAIL_ADDRESS:' $file 2>/dev/null | sed -e 's/^EMAIL_ADDRESS:[ ]*//'`
178 # Emacs/XEmacs rmail, Emacs/XEmacs gnus, XEmacs vm addresses
179 addresses
="$addresses "`grep -h '[ (]user-mail-address "[^"]*"' $file 2>/dev/null | sed -e 's/^.*[ (]user-mail-address "\([^"]*\)".*$/\1/'`
180 # XEmacs mew addresses
181 domains
=`grep -h '[ (]mew-mail-domain "[^"]*"' $file 2>/dev/null | sed -e 's/^.*[ (]mew-mail-domain "\([^"]*\)".*$/\1/'`
182 if test -n "$domains"; then
183 for domain
in $domains; do
184 addresses
="$addresses ${user}@$domain"
190 .kde
2/share
/config
/emaildefaults
)
191 addresses
="$addresses "`grep -h '^EmailAddress=' $file 2>/dev/null | sed -e 's/^EmailAddress=//'`
194 # KDE kmail addresses
195 .kde
2/share
/config
/kmailrc
)
196 addresses
="$addresses "`grep -h '^Email Address=' $file 2>/dev/null | sed -e 's/^Email Address=//'`
199 # GNOME evolution addresses
200 evolution
/config.xmldb
)
201 sedexpr0
='s/^.*<entry name="identity_address_[0-9]*" type="string" value="\([^"]*\)".*$/\1/p'
202 sedexpr1
='s/\(..\)/\\x\1/g'
204 addresses
="$addresses "`sed -n -e "$sedexpr0" < $file | while read hexstring; do printf \`echo "$hexstring" |
sed -e "$sedexpr1" -e "$sedexpr2"\
`; done`
207 # GNOME balsa addresses
209 addresses
="$addresses "`grep -h '^Address=' $file 2>/dev/null | sed -e 's/^Address=//'`
212 # OpenOffice addresses
214 addresses
="$addresses "`sed -n -e 's,^.*<mail cfg:type="string">\(.*\)</mail>.*$,\1,p' $file 2>/dev/null`
217 # StarOffice addresses
218 # Not a typo. They really write "Adress" with a single d.
219 # German orthography...
221 addresses
="$addresses "`grep -h '^User-Adress=' $file 2>/dev/null | sed -e 's/#[^#]*$//' -e 's/^.*#//'`
226 addresses
="$addresses "`grep -h '^set from="[^"]*"[ ]*$' $file 2>/dev/null | sed -e 's/^set from="\([^"]*\)"[ ]*$/\1/'`
231 domains
=`grep -h '^user-domain=' $file 2>/dev/null | sed -e 's/^user-domain=//'`
232 if test -n "$domains"; then
233 for domain
in $domains; do
234 addresses
="$addresses ${user}@$domain"
237 # The use-only-domain-name option is only used if the user-domain option is not present.
238 domains
=`grep -h '^use-only-domain-name=' $file 2>/dev/null | sed -e 's/^use-only-domain-name=//'`
239 if test "Yes" = "$domains"; then
240 addresses
="$addresses ${user}@"`echo "$hostfqdn" | sed -e 's/^[^.]*\.//'`
247 addresses
="$addresses "`grep -h '^from=.*<.*>' $file 2>/dev/null | sed -e 's/^.*<\([^<>]*\)>.*$/\1/'`
251 .ratatosk
/ratatoskrc
)
252 domains
=`grep -h '^set option(masquerade_as) ' $file 2>/dev/null | sed -e 's/^set option(masquerade_as) //'`
253 if test -n "$domains"; then
254 for domain
in $domains; do
255 addresses
="$addresses ${user}@$domain"
258 # The domain option is used only if the masquerade_as option is not present.
259 domains
=`grep -h '^set option(domain) ' $file 2>/dev/null | sed -e 's/^set option(domain) //'`
260 if test -n "$domains"; then
261 for domain
in $domains; do
262 addresses
="$addresses ${user}@${host}.$domain"
268 # ----------------------- END MAILER SPECIFIC CODE -----------------------
276 # Some Debian systems have a file /etc/mailname.
277 if test -r /etc
/mailname
; then
278 hostmailname
=`cat /etc/mailname`
279 if test -n "$hostmailname"; then
280 addresses
="$addresses ${user}@$hostmailname"
284 # SuSE Linux >= 8.0 systems have a file /etc/sysconfig/mail.
285 if test -r /etc
/sysconfig
/mail; then
286 hostmailname
=`. /etc/sysconfig/mail && echo "$FROM_HEADER"`
287 if test -n "$hostmailname"; then
288 addresses
="$addresses ${user}@$hostmailname"
292 # elm has no user-defined addresses.
293 # mailx has no user-defined addresses.
294 # mh has no user-defined addresses.
295 # They use the system default.
296 addresses
="$addresses ${user}@$hostfqdn"
298 # Normalize addresses: remove addresses without @, lowercase the part after @,
299 # and remove duplicates.
303 y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
312 for addr
in $addresses; do
314 "<"*">") addr
=`echo "$addr" | sed -e 's/^<//' -e 's/>$//'` ;;
318 addr
=`echo "$addr" | sed -n -e "$lowercase_sed"`
319 case " $naddresses " in
321 *) naddresses
="$naddresses $addr" ;;
326 addresses
="$naddresses"
328 # Now it's time to ask the user.
331 # At least two addresses.
334 for addr
in $addresses; do
336 lines
="${lines}${i} ${addr}
340 { gettext "Which is your email address?"; echo; } 1>&3
342 { gettext "Please choose the number, or enter your email address."; echo; } 1>&3
343 read answer
< /dev
/tty
348 for addr
in $addresses; do
350 if test "$i" = "$answer"; then
357 "<"*">") answer
=`echo "$answer" | sed -e 's/^<//' -e 's/>$//'` ;;
360 *" "*) { gettext "Invalid email address: invalid character."; echo; echo; } 1>&3 ; continue ;;
362 *@
*) { gettext "Invalid email address: need a fully qualified host name or domain name."; echo; echo; } 1>&3 ; continue ;;
363 *) { gettext "Invalid email address: missing @"; echo; echo; } 1>&3 ; continue ;;
365 addr
=`echo "$answer" | sed -n -e "$lowercase_sed"`
372 { gettext "Is the following your email address?"; echo; } 1>&3
373 echo " $addresses" 1>&3
374 { gettext "Please confirm by pressing Return, or enter your email address."; echo; } 1>&3
375 read answer
< /dev
/tty
376 if test -z "$answer"; then
377 addr
=`echo "$addresses" | sed -e 's/^ //'`
381 "<"*">") answer
=`echo "$answer" | sed -e 's/^<//' -e 's/>$//'` ;;
384 *" "*) { gettext "Invalid email address: invalid character."; echo; echo; } 1>&3 ; continue ;;
386 *@
*) { gettext "Invalid email address: need a fully qualified host name or domain name."; echo; echo; } 1>&3 ; continue ;;
387 *) { gettext "Invalid email address: missing @"; echo; echo; } 1>&3 ; continue ;;
389 addr
=`echo "$answer" | sed -n -e "$lowercase_sed"`
395 { gettext "Couldn't find out about your email address."; echo; } 1>&3
397 { gettext "Please enter your email address."; echo; } 1>&3
398 read answer
< /dev
/tty
400 "<"*">") answer
=`echo "$answer" | sed -e 's/^<//' -e 's/>$//'` ;;
403 *" "*) { gettext "Invalid email address: invalid character."; echo; echo; } 1>&3 ; continue ;;
405 *@
*) { gettext "Invalid email address: need a fully qualified host name or domain name."; echo; echo; } 1>&3 ; continue ;;
406 *) { gettext "Invalid email address: missing @"; echo; echo; } 1>&3 ; continue ;;
408 addr
=`echo "$answer" | sed -n -e "$lowercase_sed"`
412 *) echo "internal error" 1>&3 ; exit 1 ;;
415 # Print to standard output.