Re: migrate_sieve.pl on twiki

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I've used the following really simple AWK script to do a few simple
migrations (on hosts that were using qpopper and/or just plain unix
mail).  It beats the hell out of Perl, especially for simplicty, though
it was also pretty speedy, given that it was forking a deliver process
per message.

#! /bin/sh
#
#	unix2cyrus.sh - feed unix mailboxes to cyrus
#
# Here's a VERY simple little script to pipe individual messages from
# a unix mailbox format spool file into "deliver" so as to move that
# user's current incoming mail into their new Cyrus IMAPd "INBOX".
#
# WARNING: This script assumes the return-path header will be just one line.
#
# Usage:  unix2cyrus /var/mail/USER

awk -v user=$(basename $1) '
	BEGIN {
		FS = " ";
		pipe_cmd = "";
		deliver_cmd = "/usr/cyrus/bin/deliver -q ";
		last_line = "";
		ret_path = "";
		in_header = 1;
		header[0] = "";
		hc = 1;
	}
	$1 == "From" && last_line == "" {
		close(pipe_cmd);
		hc = 1;
		in_header = 1;
		ret_path = "root@localhost";
		next;
	}
	in_header && $0 != "" {
		if ($1 ~ /[Rr][Ee][Tt][Uu][Rr][Nn]-[Pp][Aa][Tt][Hh]:/) {
			ret_path = $2;
			gsub(/[<>]/, "", ret_path);
		} else {
			header[hc++] = $0;
		}
		next;
	}
	in_header && $0 == "" {
		in_header = 0;
		pipe_cmd = deliver_cmd "-f \"" ret_path "\" " user;
		for (i = 1; i <= hc; i++) {
			print header[i] | pipe_cmd;
		}
		print "" | pipe_cmd;
		next;
	}
	! in_header {
		last_line = $0;
		print $0 | pipe_cmd;
	}' $1


-- 
						Greg A. Woods

H:+1 416 218-0098 W:+1 416 489-5852 x122 VE3TCP RoboHack <woods@xxxxxxxxxxx>
Planix, Inc. <woods@xxxxxxxxxx>       Secrets of the Weird <woods@xxxxxxxxx>
----
Cyrus Home Page: http://cyrusimap.web.cmu.edu/
Cyrus Wiki/FAQ: http://cyrusimap.web.cmu.edu/twiki
List Archives/Info: http://asg.web.cmu.edu/cyrus/mailing-list.html

[Index of Archives]     [Cyrus SASL]     [Squirrel Mail]     [Asterisk PBX]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [KDE]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux