Integrating email and forum software

python interface

from Mailman import mm_cfg
action = sys.argv[2]   # action can be 'check' or 'set'
member = sys.argv[3]   # email address to operate on
#
#print '...'       # debugging lines
#print sys.argv    # debugging lines
#
def resolvearg(arg) :
  """if we can recognise an argument as true, return 1. Otherwise return 0"""
  if arg == 'True' : return 1
  if arg == 'true' : return 1
  if arg == '1' : return 1
  return 0
#
def mailmancheck() :
  """print the attributes of the current member in the current list"""
  global m,member
  print '...' # force a line feed so that our parser can make sense of what follows:
  if not m.isMember(member) :
    print "member=false"
    quit()
  print "member=true"
  print "digest=%s" % (m.getMemberOption(member, mm_cfg.Digests))
  print "nomail=%s" % (m.getDeliveryStatus(member))
  print "banned=%s" % (m.GetBannedPattern(member))
  if m.getMemberOption(member, mm_cfg.Moderate) : print "moderated=true"
#
#
if action == 'check' : # just print out the attributes
  mailmancheck()
  quit()
#
if action == 'set' : # change some attributes for the current user, then print out the user's attributes
  global m,member
  if not m.isMember(member) :
    print "..."
    print "member=false"
    quit()
  from Mailman import MemberAdaptor
  m.Lock()
  for arg in sys.argv[4:] :
    equals = arg.find('=')
    key = arg[0:equals]
    val = resolvearg(arg[equals+1:])
    if key == "digest" :
      if m.getMemberOption(member, mm_cfg.Digests) != val:
	m.setMemberOption(member,mm_cfg.Digests,val)
    elif key == "nomail" :
      if m.getDeliveryStatus(member) != MemberAdaptor.BYADMIN :
	if val :
	  m.setDeliveryStatus(member,MemberAdaptor.BYUSER)
	else :
	  m.setDeliveryStatus(member,MemberAdaptor.ENABLED)
#	    
  m.Save()
  m.Unlock()
  mailmancheck()
  quit()
#
# MemberAdaptor.ENABLED MemberAdaptor.BYUSER MemberAdaptor.BYADMIN MemberAdaptor.BYBOUNCE

1 Comment »

  1. […] I process the values returned from my python script. This was inspired by the work of Christian Aust. Possibly related posts: (automatically […]

    Pingback by processing python values in php « mailman-wordpress-buddypress — 2010/02/28 @ 07:58


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: