user-email 14 KB

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