• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# Prints the user's email address, with confirmation from the user.
3#
4# Copyright (C) 2001-2003, 2005, 2013 Free Software Foundation, Inc.
5#
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 3 of the License, or
9# (at your option) any later version.
10#
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.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <https://www.gnu.org/licenses/>.
18
19# Prerequisites for using @libdir@ and @localedir@.
20prefix="@prefix@"
21exec_prefix="@exec_prefix@"
22datarootdir="@datarootdir@"
23datadir="@datadir@"
24# Set variables libdir, localedir.
25libdir="@libdir@"
26localedir="@localedir@"
27
28# Support for relocatability.
29if 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.
36  while true; do
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
40      break
41    fi
42    if test "$orig_last" != "$curr_last"; then
43      break
44    fi
45    orig_installdir=`echo "$orig_installdir" | sed -e 's,/[^/]*$,,'`
46    curr_installdir=`echo "$curr_installdir" | sed -e 's,/[^/]*$,,'`
47  done
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,/$,,'`
51fi
52
53# Internationalization.
54. gettext.sh
55TEXTDOMAIN=gettext-tools
56export TEXTDOMAIN
57TEXTDOMAINDIR="$localedir"
58export TEXTDOMAINDIR
59
60# Redirect fileno 3 to interactive I/O.
61exec 3>/dev/tty
62
63# Output a prompt.
64if test $# != 0; then
65  echo "$1" 1>&3
66fi
67
68# Find the user name on the local machine.
69user=`id -u -n 2>/dev/null`
70if test -z "$user"; then
71  user="$USER"
72  if test -z "$user"; then
73    user="$LOGNAME"
74    if test -z "$user"; then
75      user=unknown
76    fi
77  fi
78fi
79
80# Find the hostname.
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`
84host=`"$libdir"/gettext/hostname --short 2>/dev/null | sed 1q`
85
86# Find the hostname.
87hostfqdn=`"$libdir"/gettext/hostname --fqdn 2>/dev/null | sed 1q`
88
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.
92cd $HOME
93files=""
94
95# ----------------------- BEGIN MAILER SPECIFIC CODE -----------------------
96
97# Mozilla Thunderbird addresses
98files="$files .thunderbird/*/prefs.js"
99
100# Mozilla addresses
101files="$files .mozilla/*/prefs.js"
102
103# Netscape 4 addresses
104files="$files .netscape/liprefs.js .netscape/preferences.js"
105
106# Netscape 3 addresses
107files="$files .netscape/preferences"
108
109# Emacs/XEmacs rmail, Emacs/XEmacs gnus, XEmacs vm addresses
110# XEmacs mew addresses
111files="$files .emacs .emacs.el"
112
113# KDE2 addresses
114files="$files .kde2/share/config/emaildefaults"
115
116# KDE kmail addresses
117files="$files .kde2/share/config/kmailrc"
118
119# GNOME evolution 2 addresses
120files="$files .gconf/apps/evolution/mail/%gconf.xml"
121
122# GNOME evolution 1 addresses
123files="$files evolution/config.xmldb"
124
125# GNOME balsa addresses
126files="$files .gnome/balsa"
127
128# StarOffice and OpenOffice addresses
129sed_dos2unix='s/\r$//'
130sed_soffice51='s,StarOffice 5\.1=\(.*\)$,\1/sofficerc,p'
131sed_soffice52='s,StarOffice 5\.2=\(.*\)$,\1/user/sofficerc,p'
132sed_ooffice='s,^OpenOffice[^=]*=\(.*\)$,\1/user/config/registry/instance/org/openoffice/UserProfile.xml,p'
133files="$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://*,/,'`
134
135# mutt addresses
136files="$files .muttrc"
137
138# pine addresses
139files="$files .pinerc"
140
141# xfmail addresses
142files="$files .xfmail/.xfmailrc"
143
144# tkrat addresses
145files="$files .ratatosk/ratatoskrc"
146
147# ----------------------- END MAILER SPECIFIC CODE -----------------------
148
149# Expand wildcards and remove nonexistent files from the list.
150nfiles=""
151for file in $files; do
152  if test -r "$file" && test ! -d "$file"; then
153    nfiles="$nfiles $file"
154  fi
155done
156files="$nfiles"
157
158addresses=""
159
160if test -n "$files"; then
161
162  for file in `ls -t $files`; do
163
164    case "$file" in
165
166# ----------------------- BEGIN MAILER SPECIFIC CODE -----------------------
167
168      # Mozilla and Mozilla Thunderbird addresses
169      .mozilla/*/prefs.js | .thunderbird/*/prefs.js)
170        addresses="$addresses "`grep -h '^user_pref("mail\.identity\..*\.useremail", ".*");$' $file 2>/dev/null | sed -e 's/^user_pref("mail\.identity\..*\.useremail", "\(.*\)");$/\1/'`
171        ;;
172
173      # Netscape 4 addresses
174      .netscape/liprefs.js | .netscape/preferences.js)
175        addresses="$addresses "`grep -h '^user_pref("mail\.identity\.useremail", ".*");$' $file 2>/dev/null | sed -e 's/^user_pref("mail\.identity\.useremail", "\(.*\)");$/\1/'`
176        ;;
177
178      # Netscape 3 addresses
179      .netscape/preferences)
180        addresses="$addresses "`grep -h '^EMAIL_ADDRESS:' $file 2>/dev/null | sed -e 's/^EMAIL_ADDRESS:[ 	]*//'`
181        ;;
182
183      .emacs | .emacs.el)
184        # Emacs/XEmacs rmail, Emacs/XEmacs gnus, XEmacs vm addresses
185        addresses="$addresses "`grep -h '[ (]user-mail-address "[^"]*"' $file 2>/dev/null | sed -e 's/^.*[ (]user-mail-address "\([^"]*\)".*$/\1/'`
186        # XEmacs mew addresses
187        domains=`grep -h '[ (]mew-mail-domain "[^"]*"' $file 2>/dev/null | sed -e 's/^.*[ (]mew-mail-domain "\([^"]*\)".*$/\1/'`
188        if test -n "$domains"; then
189          for domain in $domains; do
190            addresses="$addresses ${user}@$domain"
191          done
192        fi
193        ;;
194
195      # KDE2 addresses
196      .kde2/share/config/emaildefaults)
197        addresses="$addresses "`grep -h '^EmailAddress=' $file 2>/dev/null | sed -e 's/^EmailAddress=//'`
198        ;;
199
200      # KDE kmail addresses
201      .kde2/share/config/kmailrc)
202        addresses="$addresses "`grep -h '^Email Address=' $file 2>/dev/null | sed -e 's/^Email Address=//'`
203        ;;
204
205      # GNOME evolution 2 addresses
206      .gconf/apps/evolution/mail/%gconf.xml)
207        sedexpr0='s,^.*&lt;addr-spec&gt;\(.*\)&lt;/addr-spec&gt;.*$,\1,p'
208        addresses="$addresses "`sed -n -e "$sedexpr0" < $file`
209        ;;
210
211      # GNOME evolution 1 addresses
212      evolution/config.xmldb)
213        sedexpr0='s/^.*<entry name="identity_address_[0-9]*" type="string" value="\([^"]*\)".*$/\1/p'
214        sedexpr1='s/\(..\)/\\x\1/g'
215        sedexpr2='s,$,\\n,'
216        addresses="$addresses "`sed -n -e "$sedexpr0" < $file | while read hexstring; do printf \`echo "$hexstring" | sed -e "$sedexpr1" -e "$sedexpr2"\`; done`
217        ;;
218
219      # GNOME balsa addresses
220      .gnome/balsa)
221        addresses="$addresses "`grep -h '^Address=' $file 2>/dev/null | sed -e 's/^Address=//'`
222        ;;
223
224      # OpenOffice addresses
225      */UserProfile.xml)
226        addresses="$addresses "`sed -n -e 's,^.*<mail cfg:type="string">\(.*\)</mail>.*$,\1,p' $file 2>/dev/null`
227        ;;
228
229      # StarOffice addresses
230      # Not a typo. They really write "Adress" with a single d.
231      # German orthography...
232      */sofficerc)
233        addresses="$addresses "`grep -h '^User-Adress=' $file 2>/dev/null | sed -e 's/#[^#]*$//' -e 's/^.*#//'`
234        ;;
235
236      # mutt addresses
237      .muttrc)
238        mutt_addresses=`grep -h '^set from="[^"]*"[ 	]*$' $file 2>/dev/null | sed -e 's/^set from="\([^"]*\)"[ 	]*$/\1/'`
239        if test -n "$mutt_addresses"; then
240          addresses="$addresses $mutt_addresses"
241        else
242          # mutt uses $EMAIL as fallback.
243          if test -n "$EMAIL"; then
244            addresses="$addresses $EMAIL"
245          fi
246        fi
247        ;;
248
249      # pine addresses
250      .pinerc)
251        domains=`grep -h '^user-domain=' $file 2>/dev/null | sed -e 's/^user-domain=//'`
252        if test -n "$domains"; then
253          for domain in $domains; do
254            addresses="$addresses ${user}@$domain"
255          done
256        else
257          # The use-only-domain-name option is only used if the user-domain option is not present.
258          domains=`grep -h '^use-only-domain-name=' $file 2>/dev/null | sed -e 's/^use-only-domain-name=//'`
259          if test "Yes" = "$domains"; then
260            addresses="$addresses ${user}@"`echo "$hostfqdn" | sed -e 's/^[^.]*\.//'`
261          fi
262        fi
263        ;;
264
265      # xfmail addresses
266      .xfmail/.xfmailrc)
267        addresses="$addresses "`grep -h '^from=.*<.*>' $file 2>/dev/null | sed -e 's/^.*<\([^<>]*\)>.*$/\1/'`
268        ;;
269
270      # tkrat addresses
271      .ratatosk/ratatoskrc)
272        domains=`grep -h '^set option(masquerade_as) ' $file 2>/dev/null | sed -e 's/^set option(masquerade_as) //'`
273        if test -n "$domains"; then
274          for domain in $domains; do
275            addresses="$addresses ${user}@$domain"
276          done
277        else
278          # The domain option is used only if the masquerade_as option is not present.
279          domains=`grep -h '^set option(domain) ' $file 2>/dev/null | sed -e 's/^set option(domain) //'`
280          if test -n "$domains"; then
281            for domain in $domains; do
282              addresses="$addresses ${user}@${host}.$domain"
283            done
284          fi
285        fi
286        ;;
287
288# ----------------------- END MAILER SPECIFIC CODE -----------------------
289
290    esac
291
292  done
293
294fi
295
296# Some Debian systems have a file /etc/mailname.
297if test -r /etc/mailname; then
298  hostmailname=`cat /etc/mailname`
299  if test -n "$hostmailname"; then
300    addresses="$addresses ${user}@$hostmailname"
301  fi
302fi
303
304# SuSE Linux >= 8.0 systems have a file /etc/sysconfig/mail.
305if test -r /etc/sysconfig/mail; then
306  hostmailname=`. /etc/sysconfig/mail && echo "$FROM_HEADER"`
307  if test -n "$hostmailname"; then
308    addresses="$addresses ${user}@$hostmailname"
309  fi
310fi
311
312# elm has no user-defined addresses.
313# mailx has no user-defined addresses.
314# mh has no user-defined addresses.
315# They use the system default.
316addresses="$addresses ${user}@$hostfqdn"
317
318# Normalize addresses: remove addresses without @, lowercase the part after @,
319# and remove duplicates.
320lowercase_sed='{
321h
322s/^[^@]*@\(.*\)$/\1/
323y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/
324x
325s/^\([^@]*\)@.*/\1@/
326G
327s/\n//
328p
329}'
330naddresses=""
331for addr in $addresses; do
332  case "$addr" in
333    "<"*">") addr=`echo "$addr" | sed -e 's/^<//' -e 's/>$//'` ;;
334  esac
335  case "$addr" in
336    *@*)
337      addr=`echo "$addr" | sed -n -e "$lowercase_sed"`
338      case " $naddresses " in
339        *" $addr "*) ;;
340        *) naddresses="$naddresses $addr" ;;
341      esac
342      ;;
343  esac
344done
345addresses="$naddresses"
346
347# Now it's time to ask the user.
348case "$addresses" in
349  " "*" "*)
350    # At least two addresses.
351    lines=""
352    i=0
353    for addr in $addresses; do
354      i=`expr $i + 1`
355      lines="${lines}${i} ${addr}
356"
357    done
358    while true; do
359      { gettext "Which is your email address?"; echo; } 1>&3
360      echo "$lines" 1>&3
361      { gettext "Please choose the number, or enter your email address."; echo; } 1>&3
362      read answer < /dev/tty
363      case "$answer" in
364        *@*) ;;
365        [0-9]*)
366          i=0
367          for addr in $addresses; do
368            i=`expr $i + 1`
369            if test "$i" = "$answer"; then
370              break 2
371            fi
372          done
373          ;;
374      esac
375      case "$answer" in
376        "<"*">") answer=`echo "$answer" | sed -e 's/^<//' -e 's/>$//'` ;;
377      esac
378      case "$answer" in
379        *" "*) { gettext "Invalid email address: invalid character."; echo; echo; } 1>&3 ; continue ;;
380        *@*.*) ;;
381        *@*) { gettext "Invalid email address: need a fully qualified host name or domain name."; echo; echo; } 1>&3 ; continue ;;
382        *) { gettext "Invalid email address: missing @"; echo; echo; } 1>&3 ; continue ;;
383      esac
384      addr=`echo "$answer" | sed -n -e "$lowercase_sed"`
385      break
386    done
387    ;;
388  " "*)
389    # One address.
390    while true; do
391      { gettext "Is the following your email address?"; echo; } 1>&3
392      echo " $addresses" 1>&3
393      { gettext "Please confirm by pressing Return, or enter your email address."; echo; } 1>&3
394      read answer < /dev/tty
395      if test -z "$answer"; then
396        addr=`echo "$addresses" | sed -e 's/^ //'`
397        break
398      fi
399      case "$answer" in
400        "<"*">") answer=`echo "$answer" | sed -e 's/^<//' -e 's/>$//'` ;;
401      esac
402      case "$answer" in
403        *" "*) { gettext "Invalid email address: invalid character."; echo; echo; } 1>&3 ; continue ;;
404        *@*.*) ;;
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 ;;
407      esac
408      addr=`echo "$answer" | sed -n -e "$lowercase_sed"`
409      break
410    done
411    ;;
412  "")
413    # No address.
414    { gettext "Couldn't find out about your email address."; echo; } 1>&3
415    while true; do
416      { gettext "Please enter your email address."; echo; } 1>&3
417      read answer < /dev/tty
418      case "$answer" in
419        "<"*">") answer=`echo "$answer" | sed -e 's/^<//' -e 's/>$//'` ;;
420      esac
421      case "$answer" in
422        *" "*) { gettext "Invalid email address: invalid character."; echo; echo; } 1>&3 ; continue ;;
423        *@*.*) ;;
424        *@*) { gettext "Invalid email address: need a fully qualified host name or domain name."; echo; echo; } 1>&3 ; continue ;;
425        *) { gettext "Invalid email address: missing @"; echo; echo; } 1>&3 ; continue ;;
426      esac
427      addr=`echo "$answer" | sed -n -e "$lowercase_sed"`
428      break
429    done
430    ;;
431  *) echo "internal error" 1>&3 ; exit 1 ;;
432esac
433
434# Print to standard output.
435echo "$addr"
436