1
0
mirror of https://github.com/imapsync/imapsync.git synced 2024-11-17 16:22:29 +01:00
imapsync/W/paypal_reply/paypal_functions

254 lines
6.1 KiB
Plaintext
Raw Normal View History

2011-07-11 23:24:12 +02:00
#!/bin/sh
2013-09-27 00:00:32 +02:00
# $Id: paypal_functions,v 1.21 2013/08/21 21:46:16 gilles Exp gilles $
2011-07-11 23:24:12 +02:00
paypal_prerequisites() {
perl -mMIME::Lite -e '' || echo 'sudo aptitude install libmime-lite-perl'
perl -mMIME::Parser -e '' || echo 'sudo aptitude install libmime-tools-perl'
perl -mUnicode::MapUTF8 -e '' || echo 'sudo aptitude install libunicode-maputf8-perl'
}
paypal_init_laposte() {
user=gilles.lamiral
passfile=/g/var/pass/secret.gilles_laposte
host=imap.laposte.net
tmpdir=/g/var/paypal_reply
folder=INBOX
}
paypal_init_petite() {
user=gilles@est.belle
passfile=/g/var/pass/secret.gilles_mbox
host=p
tmpdir=/g/var/paypal_reply
folder='INBOX.03_imapsync.imapsync_paypal'
}
paypal_init_petite_INBOX() {
user=gilles@est.belle
passfile=/g/var/pass/secret.gilles_mbox
host=p
tmpdir=/g/var/paypal_reply
folder='INBOX'
}
paypal_init_petite_dev() {
user=gilles@est.belle
passfile=/g/var/pass/secret.gilles_mbox
host=p
tmpdir=/g/var/paypal_reply_dev
folder='INBOX.03_imapsync.imapsync_paypal_dev'
}
get_mail() {
# creation des r<>pertoires
mkdir -p $tmpdir/msg_in/
mkdir -p $tmpdir/msg_id/
(
cd $tmpdir/msg_in/
# recuperation des messages de la boite sans destruction des messages
# transf<73>r<EFBFBD>s
paypal_imapget --host $host --user $user --passfile $passfile \
--folder $folder
)
}
get_mail_PP1470() {
# creation des r<>pertoires
mkdir -p $tmpdir/msg_in/
mkdir -p $tmpdir/msg_id/
(
cd $tmpdir/msg_in/
# recuperation des messages de la boite sans destruction des messages
# transf<73>r<EFBFBD>s
paypal_imapget --host $host --user $user --passfile $passfile \
--folder $folder --search TEXT --search PP1470
)
}
extract_mail() {
mkdir -p $tmpdir/msg_out/
test -z "`ls $tmpdir/msg_in/`" && echo no mail && return
(
cd $tmpdir/msg_out/
test -z "`ls .`" || rm -rf *_d
paypal_mimeexplode ../msg_in/*
)
#ls -d $tmpdir/msg_out/
}
convert_utf8() {
mkdir -p $tmpdir/msg_out_utf8/
2012-04-17 00:34:41 +02:00
test -z "`ls $tmpdir/msg_out/*_d/*.txt`" && echo no mail && return
2011-07-11 23:24:12 +02:00
for f in $tmpdir/msg_out/*_d/*.txt; do
b=`basename "$f"`
d=`dirname "$f"`
bd=`basename "$d"`
d_utf8="$tmpdir/msg_out_utf8/$bd"
f_utf8="$d_utf8/$b"
test -d "$d_utf8" && continue
mkdir "$d_utf8"
if file "$f" | grep -i UTF-8 > /dev/null
then
echo copying "$f" to "$f_utf8"
cp "$f" "$f_utf8"
else
echo converting "$f" to "$f_utf8"
8859_utf8 "$f" > "$f_utf8"
fi
done
}
troncate_last_2_chars() {
2012-07-21 04:18:22 +02:00
length=`expr length "$1"`
length_2=`expr $length - 2`
expr substr "$1" 1 $length_2
2011-07-11 23:24:12 +02:00
}
build_reply() {
mkdir -p $tmpdir/msg_reply/
2012-04-17 00:34:41 +02:00
test -z "`ls $tmpdir/msg_out/`" && echo no mail && return
2011-07-11 23:24:12 +02:00
for f in $tmpdir/msg_out_utf8/*/*.txt; do
2012-07-21 04:18:22 +02:00
#echo "$f"
2011-07-11 23:24:12 +02:00
d=`dirname "$f"`
bd=`basename "$d"`
file_id=`troncate_last_2_chars $bd`
d_reply="$tmpdir/msg_reply/$file_id"
2012-07-21 04:18:22 +02:00
test -s "$d_reply/$file_id.txt" && continue
2011-07-11 23:24:12 +02:00
mkdir -p "$d_reply"
echo building "$d_reply/$file_id.txt"
2012-04-17 00:34:41 +02:00
echo paypal_build_reply "$f" "$tmpdir/msg_id/$file_id"
2011-07-11 23:24:12 +02:00
paypal_build_reply "$f" "$tmpdir/msg_id/$file_id" > "$d_reply/$file_id.txt"
2012-07-21 04:18:22 +02:00
test -s "$d_reply/$file_id.txt" || rm "$d_reply/$file_id.txt"
2011-07-11 23:24:12 +02:00
done
}
build_reply_arg() {
for f in "$@"; do
#echo "$f"
d=`dirname "$f"`
bd=`basename "$d"`
file_id=`troncate_last_2_chars $bd`
d_reply="$tmpdir/msg_reply/$file_id"
echo building "$d_reply/$file_id.txt"
echo paypal_build_reply "$f" "$tmpdir/msg_id/$file_id"
paypal_build_reply "$f" "$tmpdir/msg_id/$file_id"
done
}
2012-04-17 00:34:41 +02:00
build_invoice_arg() {
for f in "$@"; do
#echo "$f"
d=`dirname "$f"`
bd=`basename "$d"`
file_id=`troncate_last_2_chars $bd`
d_invoice="$tmpdir/invoices/$file_id"
echo building "$d_invoice/imapsync_var.tex"
echo paypal_build_invoice_from_email "$f" "$tmpdir/msg_id/$file_id"
paypal_build_invoice_from_email "$f" "$tmpdir/msg_id/$file_id"
done
}
2011-07-11 23:24:12 +02:00
debug_mode() {
2012-04-17 00:34:41 +02:00
return 0
2011-07-11 23:24:12 +02:00
return 1
}
send_reply() {
mkdir -p $tmpdir/msg_sent/
2012-04-17 00:34:41 +02:00
test -z "`ls $tmpdir/msg_reply/*/*.txt`" && echo no mail && return
2011-07-11 23:24:12 +02:00
for f in $tmpdir/msg_reply/*/*.txt; do
b=`basename "$f"`
d=`dirname "$f"`
bd=`basename "$d"`
d_sent="$tmpdir/msg_sent/$bd"
test -f "$d_sent/$b" && continue
mkdir -p "$d_sent"
2012-04-17 00:34:41 +02:00
debug_mode && echo "paypal_send $f"
2012-04-17 00:28:48 +02:00
test X"--send" = X"$1" && paypal_send --send --subscribe "$f" && touch "$d_sent/$b"
2011-07-11 23:24:12 +02:00
#test X"--send" = X"$1" && touch "$d_sent/$b"
test X"" = X"$1" && paypal_send "$f"
done
2013-09-27 00:00:32 +02:00
#mailq
2011-07-11 23:24:12 +02:00
}
paypal_all() {
paypal_prerequisites
echo "Will get messages in $tmpdir/msg_in/"
get_mail
get_mail_PP1470
echo "Done get messages in $tmpdir/msg_in/"
echo "Will extract_mail in $tmpdir/msg_out/"
extract_mail
echo "Done extract_mail in $tmpdir/msg_out/"
echo "Will converting to utf8 in $tmpdir/msg_out_utf8/"
convert_utf8
echo "Done converting to utf8 in $tmpdir/msg_out_utf8/"
echo "Will build_reply in $tmpdir/msg_reply/"
build_reply
echo "Done build_reply in $tmpdir/msg_reply/"
echo "Will send_reply $@"
send_reply "$@"
echo "Done send_reply $@"
}
#echo 'paypal_reply_petite'
paypal_reply_petite() {
echo "Doing paypal_reply_petite"
echo paypal_init_petite
paypal_init_petite
paypal_all "$@"
echo paypal_init_petite_INBOX
paypal_init_petite_INBOX
paypal_all "$@"
echo "Done paypal_reply_petite"
}
#echo 'paypal_reply_laposte'
paypal_reply_laposte() {
echo "Doing paypal_reply_laposte"
echo paypal_init_laposte
paypal_init_laposte
paypal_all "$@"
echo "Done paypal_reply_laposte"
}
paypal_all_dev() {
paypal_prerequisites
echo "Will get messages in $tmpdir/msg_in/"
get_mail
get_mail_PP1470
echo "Done get messages in $tmpdir/msg_in/"
echo "Will extract_mail in $tmpdir/msg_out/"
extract_mail
echo "Done extract_mail in $tmpdir/msg_out/"
echo "Will converting to utf8 in $tmpdir/msg_out_utf8/"
convert_utf8
echo "Done converting to utf8 in $tmpdir/msg_out_utf8/"
echo "Will build_reply in $tmpdir/msg_reply/"
build_reply
echo "Done build_reply in $tmpdir/msg_reply/"
echo "Will send_reply $@"
send_reply "$@"
echo "Done send_reply $@"
}
paypal_reply_petite_dev() {
echo "Doing paypal_reply_petite_dev"
echo paypal_init_petite_dev
paypal_init_petite_dev
paypal_all_dev "$@"
echo "Done paypal_reply_petite_dev"
}