commit fd97085140aa65d54440dad12a8807702bab0fa4
parent 1fa4fd97953e38070d33a49235a3a38108fb89d0
Author: Jaromil <jaromil@dyne.org>
Date:   Tue, 11 Sep 2012 02:53:18 +0200
compose command, completions for shells and small fixes
Diffstat:
8 files changed, 135 insertions(+), 12 deletions(-)
diff --git a/doc/jaromail-manual.org b/doc/jaromail-manual.org
@@ -315,12 +315,12 @@ open inside the mail user agent:
 And here the addressbook commands that are available from the
 commandline:
 
-| Command | Function                 |
-|---------+--------------------------|
-| abook   | edit the addressbook     |
-| list    | list the addressbook     |
-| export  | export to a VCard file   |
-| import  | import from a VCard file |
+| Command  | Function                 |
+|----------+--------------------------|
+| *abook*  | edit the addressbook     |
+| *list*   | list the addressbook     |
+| *export* | export to a VCard file   |
+| *import* | import from a VCard file |
 
 * Workflow
 
diff --git a/src/completion/README b/src/completion/README
@@ -0,0 +1,6 @@
+Shell completion quirks
+
+Zsh: _jaromail (working)
+Bash: jaromail.bash (not working yet)
+
+Manually configure by including in your completion plugin directory
diff --git a/src/completion/_jaromail b/src/completion/_jaromail
@@ -0,0 +1,61 @@
+#compdef jaro
+
+# Zsh completion for jaromail
+
+# location hardcoded is Mail
+jarodir=${HOME}/Mail
+
+_jaromail() { 
+    local curcontext="$curcontext" state line
+    typeset -A opt_args
+    typeset -alU results
+
+    _arguments \
+        '1: :->commands'\
+        '*: :->args'
+
+    case $state in
+	commands)
+            _arguments '1:Commands:(fetch send peek compose open)'
+	    ;;
+	*)
+            case $words[2] in
+
+		open|filter|search|backup|merge)
+		    for f in `ls $jarodir`; do
+			compadd "$@" "$f"; done
+		    ;;
+
+		fetch|peek)
+		    for f in `find $jarodir/jaro/Accounts -name 'imap.*'`; do
+			c=`basename ${f}|cut -d. -f2`
+			compadd "$@" "$c"
+		    done
+		    ;;
+
+		send)
+		    for f in `find $jarodir/jaro/Accounts -name 'smtp.*'`; do
+			c=`basename ${f}|cut -d. -f2`
+			compadd "$@" "$c"
+		    done
+		    ;;
+
+		compose)
+		    _files
+		    # typeset -alU names
+		    # 	names=`echo ".width 64 128
+		    # SELECT email, name FROM whitelist
+		    # WHERE name LIKE \"%$1%\"; \
+		    # SELECT email, name FROM whitelist
+		    # WHERE email LIKE \"%$1%\";" \
+		    # 	| sqlite3 -batch ${jarodir}/jaro/addressbook`
+		    # 	for n in ${(f)names}; do
+		    # 	    compadd "$@" "${n[(ws:|:)2]} <${n[(ws:|:)1]}>"
+		    # 	done
+		    ;;
+		*)  ;;
+            esac 
+    esac 
+}
+
+_jaromail "$@"+
\ No newline at end of file
diff --git a/src/completion/jaromail.bash b/src/completion/jaromail.bash
@@ -0,0 +1,42 @@
+# file: jaromail.bash
+# jaro parameter-completion for Bash
+
+# location hardcoded is Mail
+jarodir=${HOME}/Mail
+
+
+_jaro() {  #+ starts with an underscore.
+  local cur
+  # Pointer to current completion word.
+
+  COMPREPLY=()   # Array variable storing the possible completions.
+#  cur=${COMP_WORDS[COMP_CWORD]}
+  curlen=$(( ${#COMP_WORDS[@]} - 1 ))
+  cur=${COMP_WORDS[$curlen]}
+
+  case "$cur" in
+      *)
+	  COMPREPLY=( $( compgen -W 'fetch send peek compose open' -- $cur ) )
+	  ;;
+
+      open)
+	  for f in `ls $jarodir`; do
+	      COMPREPLY+=( $( compgen -W "$f" -- $cur ) )
+	  done
+	  ;;
+
+#   Generate the completion matches and load them into $COMPREPLY array.
+#   xx) May add more cases here.
+#   yy)
+#   zz)
+  esac
+
+echo 
+echo "words: cur[$cur] len[$curlen] word[${COMP_WORDS[$curlen]}]"
+echo "current array: ${COMP_WORDS[@]}"
+
+  return 0
+}
+
+complete -F _jaro -o filenames jaro
+
diff --git a/src/jaro b/src/jaro
@@ -355,10 +355,10 @@ EOF
 }
 
 # TODO: For more informations on Jaro Mail read the manual: man jaro
+typeset -A subcommands_opts
 
 main()
     {
-    local -A subcommands_opts
     ### Options configuration
     #Hi, dear developer! Are you trying to add a new subcommand, or to add some options?
     #Well, keep in mind that:
@@ -372,10 +372,12 @@ main()
     #               (it will say "option defined more than once, and he's right)
     main_opts=(a: -account=a l: -list=l q -quiet=q D -debug=D h -help=h v -version=v n -dry-run=n)
     subcommands_opts[__default]=""
+    subcommands_opts[compose]=""
     subcommands_opts[queue]=""
     subcommands_opts[fetch]=""
     subcommands_opts[send]=""
     subcommands_opts[peek]=""
+    subcommands_opts[open]=""
 
     subcommands_opts[update]=""
 
@@ -394,7 +396,7 @@ main()
     subcommands_opts[abook]=""
 
     subcommands_opts[edit]=""
-    subcommands_opts[open]=""
+    subcommands_opts[preview]=""
 
     subcommands_opts[later]=""
     subcommands_opts[backup]=""
@@ -494,6 +496,7 @@ main()
 	act "Dry run, show operations without executing them." }
 
     case "$subcommand" in
+	compose) compose ${PARAM} ;;
 	queue)   queue ${PARAM} ;;
 	fetch)   fetch ${PARAM} ;;
 	send)    send ${PARAM} ;;
@@ -516,8 +519,8 @@ main()
 	"export")  export_vcard ${PARAM} ;;
 	abook)   edit_abook ${PARAM} ;;
 
-	edit)    CLEANEXIT=0; editor ${PARAM} ;;
-	open)    CLEANEXIT=0; open_file ${PARAM} ;;
+	edit)    CLEANEXIT=0; edit_file ${PARAM} ;;
+	open)    CLEANEXIT=0; open_folder ${PARAM} ;;
 
 	backup)  backup ${PARAM} ;;
 	rmdupes) rmdupes ${PARAM} ;;
diff --git a/src/zlibs/addressbook b/src/zlibs/addressbook
@@ -96,6 +96,7 @@ WHERE email IS "${1}";
 EOF
 	return $?
 }
+
 complete() {
     func "complete from $list: ${PARAM[1]}"
 
diff --git a/src/zlibs/email b/src/zlibs/email
@@ -20,6 +20,15 @@
 # this source code; if not, write to:
 # Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+compose() {
+    # no args, open in compose mode
+    { test -z $PARAM } && {
+	${=mutt} -F $MUTTDIR/rc ""; return $? }
+    
+    ${=mutt} -F $MUTTDIR/rc "${PARAM[@]}"
+    return $?
+}
+
 queue() {
     local base;
     local tmp;
diff --git a/src/zlibs/maildirs b/src/zlibs/maildirs
@@ -60,7 +60,7 @@ maildirmake() {
 # fills up all maildirs array
 list_maildirs() {
     maildirs=()
-    for m in `find $MAILDIRS -type d | awk '
+    for m in `find -O3 $MAILDIRS/* -maxdepth 1 -type d | awk '
     /cur$/ {next}
     /tmp$/ {next}
     /new$/ {next}
@@ -69,7 +69,7 @@ list_maildirs() {
 	
 	{ maildircheck $m } && {
 	    # is a maildir
-	    { test "`find $m -type f`" != "" } && {
+	    { test "`find -O3 $m -type f`" != "" } && {
 		# and is not empty
 		maildirs+=(`basename $m`)
 	    }