9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] pop3 collector
@ 2002-07-22 11:35 matt
  0 siblings, 0 replies; only message in thread
From: matt @ 2002-07-22 11:35 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 803 bytes --]

Here's the first "working" script that mounts a remote mail system and then
transfers the mail from there to the local mail system.

It uses a control file with the username and passwords to use in the form

proto domain user password

at the moment the only supported proto is pop

the default location for this file is /usr/$user/mailcollector.boxes

the mail is injected from $user

I've only run this for a day or so but no problems so far.
of course YMMV

usage :

mailcollector [-f mailboxfile] [-k]
-f = use non-default mailbox info file
-k = leave messages on the server


It uses and abuses factotum but as far as I could tell factotum will only
store one un/pw per service per domain which fails you when you have
multiple pop boxs on the same domain.



M




[-- Attachment #2: mailcollector --]
[-- Type: application/octet-stream, Size: 2354 bytes --]

#!/bin/rc

# This script utilises the upas/fs mounted mail system to mount a remote mailbox and then 
# transfer the messages using the local smtp process.

# matt@proweb.co.uk
# 16/7/2002


# run our own copy of factotum so we dont use the current process's one
auth/factotum

# we're going to need a clean mail too
upas/fs

# read the parameters from /usr/$user/pop3
# the format of which is line separated records of space or tab separated fields :
# protocol domain username password
# Example :
# pop	pop3.aol.om	connie	secret
# 
# $key(1)	$key(2)	$key(3)	$key(4)
# 

pwfile = /usr/$user/mailcollector.boxes
keep = 0
# -f pwfile  <- use a different pw file
while(~ $1 -*){
	switch($1){
	case -f:
		shift
		pwfile = $1
	case -k:
		keep = '1'
	}
	shift
}

{
	key = `{read}
	num_msgs = 0
	while(test $#key '!=' '0') {  # die when null/blank line
		switch($key(1)) {
		# made it a switch for expansion and comments 
		case pop :
			# tell stdout what we're doing
			echo $key(3) at $key(2)

			# insert a key into the local factotum 
			echo 'key proto=pass service=' ^$key(1) ^' dom=' ^$key(2) ^' user=' ^$key(3) ^' !password=' ^$key(4) > /mnt/factotum/ctl

			# open the mailbox, it get's mounted as /mail/fs/$key(3) 
			echo 'open /pop/'^$key(2) ^' ' ^$key(3) > /mail/fs/ctl

			
			msgs = /mail/fs/$key(3)
			if (test -d $msgs) {									# make sure it's a directory (to skip ctl)
				for (msg in `{ls $msgs}) {							# get the message list
					if (test -d $msg) {							# if message is directory
						cat $msg/raw | upas/send -r -b $user		# get upas to send it to $user from $user
						
						num_msgs = `{echo $num_msgs + 1 | bc}
						echo From: `{cat $msg/from}				# Tell stdout
						echo Subject : `{cat $msg/subject}
						if (test $keep '=' '0')
							rm $msg							# delete message from the remote server
					}
					
				}
			} 
			if not {
				echo no mail									# poor you, at least you got no spam
			}
			echo 'close ' ^$key(3) > /mail/fs/ctl						# close the mailbox

			# delete the key from factotum so that we can process multiple pop3 boxes on the same domain
			echo 'delkey proto=pass service=' ^$key(1) ^' dom=' ^$key(2) ^' user=' ^$key(3) > /mnt/factotum/ctl
		}
		key = `{read}
	}

} < $pwfile

echo $num_msgs mails processed.





^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-07-22 11:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-22 11:35 [9fans] pop3 collector matt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).