diff --git a/tailbone/views/email.py b/tailbone/views/email.py index 58ef43ed..6e12e972 100644 --- a/tailbone/views/email.py +++ b/tailbone/views/email.py @@ -205,6 +205,28 @@ class ProfilesView(MasterView): return kwargs +class RecipientsType(colander.String): + """ + Custom schema type for email recipients. This is used to present the + recipients as a "list" within the text area, i.e. one recipient per line. + Then the list is collapsed to a comma-delimited string for storage. + """ + + def serialize(self, node, appstruct): + if appstruct is colander.null: + return colander.null + recips = parse_list(appstruct) + return '\n'.join(recips) + + def deserialize(self, node, cstruct): + if cstruct == '' and self.allow_empty: + return '' + if not cstruct: + return colander.null + recips = parse_list(cstruct) + return ', '.join(recips) + + class EmailProfileSchema(colander.MappingSchema): prefix = colander.SchemaNode(colander.String()) @@ -215,11 +237,11 @@ class EmailProfileSchema(colander.MappingSchema): replyto = colander.SchemaNode(colander.String(), missing='') - to = colander.SchemaNode(colander.String()) + to = colander.SchemaNode(RecipientsType()) - cc = colander.SchemaNode(colander.String(), missing='') + cc = colander.SchemaNode(RecipientsType(), missing='') - bcc = colander.SchemaNode(colander.String(), missing='') + bcc = colander.SchemaNode(RecipientsType(), missing='') enabled = colander.SchemaNode(colander.Boolean())