+#!/bin/sh -
+
+set -e
+
+# Check servername, username, password are supplied.
+if [ $# -lt 3 ]; then
+ echo "Usage: $0 servername username password"
+ echo "eg: $0 wiki.example.com fred secret"
+ exit 1
+fi
+servername=$1
+username="$2"
+password="$3"
+shift 3
+
+# Cookie jar.
+cj=/tmp/$$.cookies
+
+curl="curl -c $cj -o /dev/null -s -w %{http_code}"
+
+# Login to the remote server. The side-effect of this is just to put
+# a cookie in the cookie jar.
+rv=`$curl -F username="$username" -F password="$password" http://$servername/_bin/login.cmo`
+if [ "$rv" != 200 ]; then
+ echo "Login failed. Username or password incorrect."
+ exit 1
+fi
+
+curl="curl -b $cj -c $cj -o /dev/null -s -w %{http_code}"
+
+# Import the mail messages.
+for m in "$@"; do
+ rv=`$curl -F file="<$m" http://$servername/_bin/mail_import.cmo`
+ if [ "$rv" != 200 ]; then
+ echo "Warning: Failed to import message $m"
+ fi
+done
+
+# Remove any temporary files.
+rm -f $cj