Hmm. Not entirely sure I'd throw XML into the situation; if I were doing it all over again, I'd probably just lob stuff into a database with a schema something like:
Code:
class Recipe:
user = models.ForeignKey(User) # the recipe belongs to this user
order = models.IntegerField() # sort order for this recipe
flags = models.CharField() # flags; could probably go to town with a M2M field or something, too
action = models.TextField() # exactly one action line
@property
def block(self):
"Returns a configuration stanza appropriate for .procmailrc"
recipe = (":0 %s\n" % self.flags) if self.flags else ":0\n"
for condition in self.condition_set.all():
recipe += "* %s\n" % condition
recipe += self.action + "\n"
return recipe
class Condition:
condition = models.TextField() # the regexp to match
recipe = models.ForeignKey(Recipe) # the condition belongs to this recipe
# instantiated like:
my_recipe = Recipe.objects.create(
user = User.objects.get(username='jboehner')
order = 10 # like MX records ;-)
flags = 'c' # generate a carbon copy
action = '! president@whitehouse.gov' # forward to POTUS
)
my_recipe.condition_set.create(
condition = "^From: vicepresident@whitehouse.gov" # match that sneaky under-the-table-dealin' joe
)
Then simply, as a user that can write to all of these locations:
Code:
from models import User, Recipe
for user in User.objects.filter(recipes_set__count__gt=0):
with open('%s/.procmailrc' % user.homedir, 'w') as fp:
for recipe in Recipe.objects.filter(user=user).order_by('order'):
fp.write(recipe.block)
And bam, out they come. Apologies for the Django-specificness here; it was the easiest way to bang this out in a hurry. Testing, error handling, user interfacing, not writing out all the .procmailrc files every time this runs, the inevitable race conditions, and all that other stuff are left as an exercise for the reader.
I think Webmin has a module that does this -- it might be worth looking through its source for inspiration, too.
_________________
Code:
/* TODO: need to add signature to posts */