Bumped version for release.
[cocanwiki.git] / tools / import_mail.sh
1 #!/bin/sh -
2
3 set -e
4
5 # Check servername, username, password are supplied.
6 if [ $# -lt 3 ]; then
7     echo "Usage: $0 servername username password"
8     echo "eg: $0 wiki.example.com fred secret"
9     exit 1
10 fi
11 servername=$1
12 username="$2"
13 password="$3"
14 shift 3
15
16 # Cookie jar.
17 cj=/tmp/$$.cookies
18
19 curl="curl -c $cj -o /dev/null -s -w %{http_code}"
20
21 # Login to the remote server.  The side-effect of this is just to put
22 # a cookie in the cookie jar.
23 rv=`$curl -F username="$username" -F password="$password" http://$servername/_bin/login.cmo`
24 if [ "$rv" != 200 ]; then
25     echo "Login failed. Username or password incorrect."
26     exit 1
27 fi
28
29 curl="curl -b $cj -c $cj -o /dev/null -s -w %{http_code}"
30
31 # Import the mail messages.
32 for m in "$@"; do
33     rv=`$curl -F file="<$m" http://$servername/_bin/mail_import.cmo`
34     if [ "$rv" != 200 ]; then
35         echo "Warning: Failed to import message $m"
36     fi
37 done
38
39 # Remove any temporary files.
40 rm -f $cj