jaromail

a commandline tool to easily and privately handle your e-mail
git clone git://parazyd.org/jaromail.git
Log | Files | Refs | Submodules | README

commit 1dd5b78797239d9bb87f0caebc8d01491b9fe24e
parent 8f6c54042e14001138a8dfbc8afbc0891be308fa
Author: Jaromil <jaromil@dyne.org>
Date:   Wed, 26 Sep 2012 23:55:19 +0200

fixes to online checks

Diffstat:
Msrc/jaro | 4++++
Msrc/zlibs/email | 11+++++++++--
Msrc/zlibs/helpers | 12+++++++++---
3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/src/jaro b/src/jaro @@ -451,6 +451,8 @@ main() subcommands_opts[ramdisk]="" subcommands_opts[source]="" + subcommands_opts[isonline]="" + ### Detect subcommand local -aU every_opts #every_opts behave like a set; that is, an array with unique elements for optspec in $subcommands_opts$main_opts; do @@ -576,6 +578,8 @@ main() ramdisk) ramdisk ${PARAM} ;; + isonline) is_online ${=PARAM}; exitcode=$? ;; + 'source') CLEANEXIT=0; return 0 ;; __default) func "no command provided" autostart ${PARAM} diff --git a/src/zlibs/email b/src/zlibs/email @@ -222,12 +222,16 @@ send() { return 1 } - notice "Sending out ${mailnum} mails via ${type}.${account}" - # defaults { test -z $auth } && { auth=plain } { test -z $port } && { port=25 } + is_online ${host} ${port} + { test $? = 0 } || { return 1 } + + notice "Sending out ${mailnum} mails via ${type}.${account}" + + { test $DRYRUN != 1 } && { ask_password $login $host { test $? != 0 } && { @@ -284,6 +288,9 @@ peek() { return 1 } + is_online ${host} ${port} + { test $? = 0 } || { return 1 } + notice "Peek into remote imap account $name" folder="" diff --git a/src/zlibs/helpers b/src/zlibs/helpers @@ -139,20 +139,22 @@ open_file() { ######################### ## check if we are online is_online() { + func "Test if we are online" { test "$FORCE" = "1" } && { act "Internet check skipped (--force in use)" return 0 } _res=1 _host=${1:-8.8.8.8} - _port=${2:-} + _port=${2:-NONE} _mode=inet # or host - { test "$port" = "" } || { _mode=host } + { test "$_port" = "NONE" } || { _mode=host } case $_mode in inet) - ping -c1 -n 8.8.8.8 2>&1 > /dev/null + func "trying to ping ${_host}" + ping -c1 -n ${_host} 2>&1 > /dev/null { test $? = 0 } || { error "Internet seems unreachable" act "Network connection is checked with a ping to 8.8.8.8" @@ -160,8 +162,10 @@ is_online() { error "Operation aborted." exit 1 } + act "Internet seems to be reachable" ;; host) + func "trying to connect ${_host} port ${_port}" nc -w 16 -z ${_host} ${_port} > /dev/null { test $? = 0 } || { error "Host unreachable: $_host" @@ -170,8 +174,10 @@ is_online() { error "Operation aborted." return 1 } + act "Host $_host responds on port $_port" ;; esac + return 0 }