On Wed, 2003-10-29 at 16:24, Rob Siemborski wrote:
> On Wed, 29 Oct 2003, Alexander Brill wrote:
> 
> > Is there an easy way to deliver a message to all my users? Would be
> > handy in sending out system messages.
> 
> This is an MTA level thing, but there are a few ways to generate a list of
> all your users to mail to.
> 
> (one is to log into cyrus as an admin, and issue 'x LIST "" "user.%"')
> 
> You can probably do this with a simple cyradm script to get the results
> you need.


Yeah.. I wrote a quick python-script to do it all. I attached it in case
anyone else would like the same thing.

-- 
Alexander Brill <[EMAIL PROTECTED]>
http://www.project23.no
PGP-key: http://www.nettstudio.no/firma/Library/PGP/alex_pgp/view
import imaplib, sys
"""
A script to get all mailboxes and deliver a message to them. Useful for sending out system messages.

Alexander Brill <[EMAIL PROTECTED]>
"""


class Imap:
	def __init__(self, username, password, host):
		self.imap = imaplib.IMAP4(host)
		self.imap.login(username,password)

	def getUsers(self):
		""" Returns a list of users. """
		users = []
		status, data = self.imap.list(pattern='"user.\%"')
		if not status == "OK":
			return None
		for user in data:
			users.append(user.split()[2].replace('"',"").replace("user.",""))
		return users

	def append(self, user, message):
		""" Append message to the user's mailbox"""
		user = "user.%s" % user
		status, data = self.imap.append(user, None, None, message)
		return status,data

if __name__ == "__main__":
	if not len(sys.argv) == 5:
		print "Usage: %s <username> <password> <hostname> <message>" % sys.argv[0]
		sys.exit(1)
	username = sys.argv[1]
	password = sys.argv[2]
	hostname = sys.argv[3]
	msg = open(sys.argv[4], "r").read()
	imap = Imap(username, password, hostname)
	users = imap.getUsers()
	if users:
		print "Sending message to %d users:" % len(users)
		for user in users:
			status, data = imap.append(user, msg)
			if status == "OK":
				data = ""
			print user, status, data

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to