# Default setting used if the domain name can not be found, or if something goes # wrong. #default='/usr/sbin/sendmail -oem -oi' # Make matching case insensitive shopt -s nocasematch # Regexp matching the host name of the machine this script should run on. (Other # machines get the default above). run_hosts='^baradur|mordor$' # The file /etc/resolv.conf is egrepped against patterns in the array # "resolv_regexp" (A leading "!" denotes negation of match). If a match is found # the corresponding msmtp account (from the accounts array) is used. # # If no match is found, then this script gets the domain name. This could be # time consuming if it is not found in /etc/resolv.conf, as it involves a name # server lookup. The domain name is then matched against the (bash) regexp's in # the array "dom_regexp". If a match is found, the corresponding msmtp account # (from the accounts array) is used. # # Patterns are matched in the order they are defined. If no pattern matches, # then the script produces no output. # # An account named "ssh" is special. It calls the function ssh_tunnel when such # an account is selected. # # The following are the settings I use on my laptop. # Use default account if we could not get the domain name. accounts+=(default) dom_regexp+=('^$') resolv_regexp+=('!nameserver') # Use account 'stanford' from within the Stanford.EDU domain. accounts+=(stanford) #dom_regexp+=('^(Stanford\.EDU|gi1242.net)$') dom_regexp+=('^Stanford\.EDU$') resolv_regexp+=('^(nameserver[[:space:]]+171\.64\.7\.|search.*[[:space:]]stanford.edu)') # ri.cox.net seems to have firewalled port 25, so use ssh tunnelling in this # domain. (The function ssh_tunnel (called automatically) sets up the tunnel) accounts+=(ssh) dom_regexp+=('(^|\.)(ri\.cox\.net|near.uiuc.edu)$') resolv_regexp+=('') # From outside the Stanford.EDU domain, use account 'roam' with Kerberos # authentication. It involves typing my password once a day (when my kerberos # tickets expire), but is faster than ssh tunneling. (This requires traffic # through port 25 to not be firewalled) accounts+=(roam) dom_regexp+=('.') resolv_regexp+=('') # Ignore case while matching. shopt -s nocasematch # Function called when account named "ssh" is used function ssh_tunnel() { debug "Starting SSH tunnel" # Kill an already running tunnel (connection might be inactive) pkill -f '^ssh.*8025:math:25' # Create a tunnel to mail server. Forward local port 8025 to remote 25 ssh -N -f -L 8025:math:25 math & } # # End user settings # # vim: set ft=sh: