commit ee5f947613646b480bde58198192eb68d527af88
parent 18c2e4e76ee408f6a21b29024f1650829a5b3f81
Author: Jaromil <jaromil@dyne.org>
Date: Sun, 3 Jun 2012 18:58:18 +0200
use /dev/shm to store tmp files in RAM when possible
Diffstat:
M | src/jaro | | | 86 | +++++++++++++++++++++++++++++++++++++++++++++---------------------------------- |
1 file changed, 49 insertions(+), 37 deletions(-)
diff --git a/src/jaro b/src/jaro
@@ -33,12 +33,22 @@ QUIET=0
DEBUG=0
DRYRUN=0
CLEANEXIT=1
+TMPRAM=0
# which command to use when creating dirs
mkdir="`which mkdir` -m 700 -p"
# date stamp
datestamp=`date '+%d%b%y'`
-
+# temporary directory
+touch /dev/shm/jaromail.test.tmp > /dev/null
+if [ $? = 0 ]; then
+ # we can use volatile ram
+ rm -f /dev/shm/jaromail.test.tmp
+ TMPDIR=/dev/shm/jaromail.$USER.$datestamp
+ TMPRAM=1
+else
+ TMPDIR=$WORKDIR/tmp
+fi
##########################
@@ -94,6 +104,8 @@ case $(uname) in
error "Running on an unknown operating system, assuming GNU" ;;
esac
+{ test $TMPRAM = 1 } && {
+ act "Using temporary directory in volatile RAM" }
if [ -z $MAILDIRS ]; then
# check if we are inside the directory
@@ -115,7 +127,7 @@ ${=mkdir} $WORKDIR
chmod 700 $WORKDIR
# make sure we have a temp and cache dir
-${=mkdir} "$WORKDIR/tmp"
+${=mkdir} "$TMPDIR"
${=mkdir} "$WORKDIR/cache"
${=mkdir} "$WORKDIR/log"
${=mkdir} "$WORKDIR/certs"
@@ -125,9 +137,10 @@ MUTTDIR=$WORKDIR/.mutt
cleanexit() {
func "Clean exit procedures"
- for f in `ls $WORKDIR/tmp/ | grep -v '.lock$'`; do
- unlink $WORKDIR/tmp/$f
+ for f in `ls $TMPDIR/ | grep -v '.lock$'`; do
+ unlink $TMPDIR/$f
done
+ { test $TMPRAM = 1 } && { rmdir $TMPDIR }
unset typeset -h name login host protocol port password auth folders accountopt
}
# make sure tmp is wiped from sensitive data in case of sigINT
@@ -616,47 +629,47 @@ fetch() {
unset password all; return 1
}
- newlock $WORKDIR/tmp/$host.fetch
- cat <<EOF > $WORKDIR/tmp/$host.fetch
+ newlock $TMPDIR/$host.fetch
+ cat <<EOF > $TMPDIR/$host.fetch
poll $host with proto IMAP user "$login" there with password "$password"
EOF
unset password
if ! [ -z $accountopt ]; then # add option configuration
- echo "${accountopt}" >> $WORKDIR/tmp/$host.fetch; fi
+ echo "${accountopt}" >> $TMPDIR/$host.fetch; fi
if ! [ -z $folders ]; then # add folder configuration
- echo "folder ${folders}" >> $WORKDIR/tmp/$host.fetch; fi
+ echo "folder ${folders}" >> $TMPDIR/$host.fetch; fi
- cat <<EOF >> $WORKDIR/tmp/$host.fetch
+ cat <<EOF >> $TMPDIR/$host.fetch
ssl warnings 3600 and wants mda "procmail -m $PROCMAILDIR/rc"
EOF
if [ "$cert" = "check" ]; then
- cat <<EOF >> $WORKDIR/tmp/$host.fetch
+ cat <<EOF >> $TMPDIR/$host.fetch
sslcertck sslcertpath '$WORKDIR/certs'
EOF
fi
- cat <<EOF >> $WORKDIR/tmp/$host.fetch
+ cat <<EOF >> $TMPDIR/$host.fetch
antispam 571 550 501 554
EOF
# try login without doing anything
- fetchmail -c -f $WORKDIR/tmp/$host.fetch
+ fetchmail -c -f $TMPDIR/$host.fetch
# examine result
case $? in
1)
notice "No mails for $name"
- unlock $WORKDIR/tmp/$host.fetch
+ unlock $TMPDIR/$host.fetch
return 1
;;
2)
error "Invalid or unknown certificate for $host"
- unlock $WORKDIR/tmp/$host.fetch
+ unlock $TMPDIR/$host.fetch
return 1
;;
3)
error "Invalid password for user $login at $host"
- unlock $WORKDIR/tmp/$host.fetch
+ unlock $TMPDIR/$host.fetch
return 1
;;
*) ;;
@@ -672,11 +685,11 @@ EOF
fi
act "please wait while downloading mails..."
- cat $WORKDIR/tmp/$host.fetch | fetchmail -f -
+ cat $TMPDIR/$host.fetch | fetchmail -f -
# TODO: substitute this with cat conf | fetchmail -f -
# to avoid writing the password in clear on filesystem
- unlock $WORKDIR/tmp/$host.fetch
+ unlock $TMPDIR/$host.fetch
total=`mailstat -k $WORKDIR/log/procmail.log | tail -n1 | awk '{print $2}'`
briefing=`mailstat -kt $WORKDIR/log/procmail.log |awk '!/procmail/ { print " " $2 "\t" $3 }'|sort -nr`
@@ -721,8 +734,8 @@ send() {
unset password all; return 1
}
- newlock $WORKDIR/tmp/$host.send
- cat <<EOF > $WORKDIR/tmp/$host.send
+ newlock $TMPDIR/$host.send
+ cat <<EOF > $TMPDIR/$host.send
account default
from ${email}
user ${login}
@@ -742,7 +755,7 @@ EOF
lock ${smtp}
recipients="`cat ${smtp}`"
act "To: ${recipients}"
- msmtp -C $WORKDIR/tmp/$host.send -- ${=recipients} < "${mail}"
+ msmtp -C $TMPDIR/$host.send -- ${=recipients} < "${mail}"
if [ $? != 0 ]; then
error "Error sending mail, skipped"
unlock ${smtp}
@@ -754,7 +767,7 @@ EOF
locked_unlink ${smtp} &
fi
done
- unlock $WORKDIR/tmp/$host.send
+ unlock $TMPDIR/$host.send
return 0
}
@@ -795,15 +808,14 @@ peek() {
error "Error retrieving password for $login on $host"
unset password all; return 1
}
- newlock $WORKDIR/tmp/muttpasswd
- cat <<EOF >> $WORKDIR/tmp/muttpasswd
+ newlock $TMPDIR/muttpasswd
+ cat <<EOF >> $TMPDIR/muttpasswd
set imap_pass = "${password}"
-\`$WORKDIR/bin/dotlock -u $WORKDIR/tmp/muttpasswd; echo 'set imap_peek=yes'\`
+\`$WORKDIR/bin/dotlock -u $TMPDIR/muttpasswd; echo 'set imap_peek=yes'\`
EOF
unset password
- (sleep 5; unlink $WORKDIR/tmp/muttpasswd)&
+ (sleep 5; unlink $TMPDIR/muttpasswd)&
mutt -F $MUTTDIR/rc -f ${iproto}://${ilogin}@${host}${folder}
- # TODO automatic input of password in mutt
return $?
}
@@ -857,7 +869,7 @@ macro index,pager A "<pipe-message>$WORKDIR/bin/jaro -l Whitelist.txt -q forget<
macro index,pager z "<pipe-message>$WORKDIR/bin/jaro -l Blacklist.txt -q learn<enter>" "add sender to blacklist"
macro index,pager Z "<pipe-message>$WORKDIR/bin/jaro -l Blacklist.txt -q forget<enter>" "remove sender from blacklist
-\`test -r $WORKDIR/tmp/muttpasswd && echo "source $WORKDIR/tmp/muttpasswd"\`
+\`test -r $TMPDIR/muttpasswd && echo "source $TMPDIR/muttpasswd"\`
EOF
if [ -r $MUTTDIR/general ]; then
@@ -996,9 +1008,9 @@ EOF
echo " \\" >> $MUTTDIR/mboxes
echo " +ml.unsorted +unsorted" >> $MUTTDIR/mboxes
- uniq $MUTTDIR/mboxes > $WORKDIR/tmp/mboxes
- mv $WORKDIR/tmp/mboxes $MUTTDIR/mboxes
- rm -f $WORKDIR/tmp/mboxes
+ uniq $MUTTDIR/mboxes > $TMPDIR/mboxes
+ mv $TMPDIR/mboxes $MUTTDIR/mboxes
+ rm -f $TMPDIR/mboxes
# conclude
cat <<EOF >> $PROCMAILDIR/rc
@@ -1062,12 +1074,12 @@ forget() {
| tr 'A-Z' 'a-z' \
| sed 's/.*\W\([0-9a-z_.-]\+@[0-9a-z_.-]\+\).*/\1/'`
func "forgetting address: $addr"
- newlock $WORKDIR/tmp/forget-addr
+ newlock $TMPDIR/forget-addr
awk "/$addr/"' { next; }
{ print $0 }' ${WORKDIR}/$listaddr \
- >> $WORKDIR/tmp/forget-addr
- cp $WORKDIR/tmp/forget-addr ${WORKDIR}/$listaddr
- unlock $WORKDIR/tmp/forget-addr
+ >> $TMPDIR/forget-addr
+ cp $TMPDIR/forget-addr ${WORKDIR}/$listaddr
+ unlock $TMPDIR/forget-addr
}
###################
@@ -1112,18 +1124,18 @@ backup() {
}
rmdupes() {
- newlock $WORKDIR/tmp/$datestamp.rmdupes
+ newlock $TMPDIR/$datestamp.rmdupes
for folder in ${=PARAM}; do
{ test ! -r $folder } && { folder=$MAILDIRS/$folder }
{ test ! -r $folder } && { error "Maildir not found: $folder"; continue }
notice "Removing duplicates in $folder"
c=0
for i in `find ${folder} -type f`; do
- formail -D 100000 $WORKDIR/tmp/$datestamp.rmdupes <$i \
+ formail -D 100000 $TMPDIR/$datestamp.rmdupes <$i \
&& rm $i && c=`expr $c + 1`
done
done
- unlock $WORKDIR/tmp/$datestamp.rmdupes
+ unlock $TMPDIR/$datestamp.rmdupes
notice "$c duplicates found and deleted"
}