commit 0433481b6044bcffaa0bd7bc39e3fb1c9a5642ef
parent 7f82a23c1d78318e89867b7439d4f6a7e6bf0aa1
Author: Jaromil <jaromil@dyne.org>
Date: Thu, 16 Oct 2014 19:51:11 +0200
several fixes to imap: plain, custom port. also fixes to imap listfolders and getsize
Diffstat:
3 files changed, 58 insertions(+), 34 deletions(-)
diff --git a/src/jaro b/src/jaro
@@ -736,15 +736,23 @@ main()
imapcmd="$1"
case $1 in
getsize)
- read_account
+ read_account $account
ask_password
- imap_get_size
+ bytes_total=`imap_get_size "$2"`
+ notice "Size of account $login on $host"
+ act "$bytes_total bytes"
+ mib_total=$(( $bytes_total / 1048576 ))
+ act "$mib_total MB (MiB)"
exitcode=$?
;;
listfolders)
- read_account
+ read_account $account
ask_password
- imap_list_folders
+ folders=(`imap_list_folders`)
+ notice "List of folders for $login on $host"
+ for f in $folders; do
+ print "$f"
+ done
exitcode=$?
;;
# interactive)
diff --git a/src/zlibs/email b/src/zlibs/email
@@ -156,10 +156,10 @@ queue() {
fetchall() {
notice "Fetching all accounts in $MAILDIRS"
res=0
- for i in `${=find} $WORKDIR/Accounts -type f | grep -v README`; do
+ accts=`${=find} $MAILDIRS/Accounts -type f | grep -v README`
+ notice "Fetching mail for all accounts: ${#accts} found"
+ for i in ${(f)accts}; do
account=`basename $i`
- account_type="${account[(ws:.:)1]}"
- account="${account[(ws:.:)2]}"
fetch
if [ $? != 0 ]; then res=1; fi
# returns an error if just one of the accounts did
@@ -206,15 +206,22 @@ fetch() {
fmconf=("poll $imap with proto IMAP user \"$login\" there with password \"$password\"")
- unset password
-
if ! [ -z $accountopt ]; then # add option configuration
fmconf+=(" ${accountopt} "); fi
- if ! [ -z $folders ]; then # add folder configuration
- fmconf+=(" folder ${folders} "); fi
+ # if no folders specified, use all
+ [[ "$folders" == "" ]] && {
+ folders=(`imap_list_folders`) }
+ act "${#folders} folders found"
+
+ unset password
+
+ [[ ${#folders} == "0" ]] && { return 1 }
+
+ # add folder configuration
+ fmconf+=(" folder ${=folders} ");
- fmconf+=(" ssl warnings 3600 and wants mda \"jaro -q deliver\" ")
+ fmconf+=(" ${transport} warnings 3600 and wants mda \"jaro -q deliver\" ")
if [ "$cert" = "check" ]; then
# we now use system-wide certs
@@ -228,6 +235,11 @@ fetch() {
{ test $? = 0 } || {
error "planning to delete mails from server, account option: $accountopt" }
+ print $fmconf
+# QUAAA
+# return 0
+
+
# try login without doing anything
print "$fmconf" | fetchmail -c -f -
res=$?
@@ -438,7 +450,7 @@ peek() {
folder=""
if ! [ -z ${1} ]; then
- folder="/${1}"
+ folder="${1}"
act "opening folder ${folder}"
fi
@@ -484,7 +496,7 @@ EOF
cp /dev/null "$TMPDIR/muttpass"
unlink "$tmp" # secure delete in ram
) &
- ${=mutt} -F $MUTTDIR/rc -f ${iproto}://${ilogin}@${imap}${folder}
+ ${=mutt} -F $MUTTDIR/rc -f ${iproto}://${ilogin}@${imap}:${imap_port}/${folder}
} # DRYRUN
return $?
diff --git a/src/zlibs/imap b/src/zlibs/imap
@@ -35,18 +35,13 @@ imap_list_folders() {
func "imap_list_folders()"
check_imap && return 1
- notice "Querying the list of folders for $login on $imap"
-
- query="
-B00000 CAPABILITY
+ query="B00000 CAPABILITY
B00001 LOGIN \"${login}\" \"${password}\"
B00002 LIST \"\" *
-B00003 LOGOUT
-"
+B00003 LOGOUT"
response=`print $query | run_imap_query`
folders=`print $response | awk '
-/^\* LIST/ { gsub(/"/, "", $5); print $5 }
-'`
+/^\* LIST/ { gsub(/"/, "", $5); print $5 }' | tr -d '\r'`
print $folders
}
@@ -65,29 +60,38 @@ imap_get_size() {
} || {
folders=("$1") }
- query="
-B00000 CAPABILITY
-B00001 LOGIN \"${login}\" \"${password}\"
-"
+ query="B00000 CAPABILITY
+B00001 LOGIN \"${login}\" \"${password}\""
+
c=1
for f in ${folders}; do
+ func "folder: $f"
[[ "$f" == "" ]] && continue
c=$(( $c + 1 ))
- query="$query\nB0000$c SELECT \"${f}\""
+
+ query="$query
+B0000$c SELECT \"${f}\""
+
c=$(( $c + 1 ))
- query="$query\nB0000$c FETCH 1:* (FLAGS RFC822.SIZE)"
+ query="$query
+B0000$c FETCH 1:* (RFC822.SIZE)"
+
done
c=$(( $c + 1 ))
- query="$query\nB0000$c LOGOUT"
+ query="$query
+B0000$c LOGOUT"
+ # print $query
+ # print "$query" | run_imap_query
+ # return 0
+
result=(`print "$query" | run_imap_query | awk '
/^\*.*FETCH.*RFC822.SIZE/ { gsub(/\)/, "", $NF); print $NF }' | tr -d '\r'`)
+
bytes_total=0
+ typeset -A fsizes
for i in $result; do
-# print $i
+ # TODO: list sizes per-folder
bytes_total=$(( $bytes_total + $i ))
done
- notice "Size of account $login on $host"
- act "$bytes_total bytes"
- mib_total=$(( $bytes_total / 1048576 ))
- act "$mib_total MB (MiB)"
+ print $bytes_total
}