[mail] allow to specify SMTP's MAIL FROM address to config.sendmails(). Closes #3373620
Also modify testlib.Email so we don't loose this information and may test it.
sync_schema_props_perms('defaultval')defconvert_defaultval(cwattr,default):fromdecimalimportDecimalimportyamsfromcubicwebimportBinaryifdefaultisNone:returnatype=cwattr.to_entity[0].nameifatype=='Boolean':# boolean attributes with default=False were stored as ''assertdefaultin('True','False',''),repr(default)default=default=='True'elifatypein('Int','BigInt'):default=int(default)elifatype=='Float':default=float(default)elifatype=='Decimal':default=Decimal(default)elifatypein('Date','Datetime','TZDatetime','Time'):try:# handle NOW and TODAY, keep them stored as stringsyams.KEYWORD_MAP[atype][default.upper()]default=default.upper()exceptKeyError:# otherwise get an actual date or datetimedefault=yams.DATE_FACTORY_MAP[atype](default)else:assertatype=='String',atypedefault=unicode(default)returnBinary.zpickle(default)dbh=repo.system_source.dbhelperdriver=config.sources()['system']['db-driver']ifdriver=='postgres'ordriver.startswith('sqlserver'):sql('ALTER TABLE cw_cwattribute ADD new_defaultval %s'%dbh.TYPE_MAPPING['Bytes'])forcwattrinrql('CWAttribute X').entities():olddefault=cwattr.defaultvalifolddefaultisnotNone:req="UPDATE cw_cwattribute SET new_defaultval = %(val)s WHERE cw_eid = %(eid)s"args={'val':dbh.binary_value(convert_defaultval(cwattr,olddefault).getvalue()),'eid':cwattr.eid}sql(req,args,ask_confirm=False)sql('ALTER TABLE cw_cwattribute DROP COLUMN cw_defaultval')ifconfig.sources()['system']['db-driver']=='postgres':sql('ALTER TABLE cw_cwattribute RENAME COLUMN new_defaultval TO cw_defaultval')else:sql("sp_rename 'cw_cwattribute.new_defaultval', 'cw_defaultval', 'COLUMN'")elifdriver=='sqlite':importrecreate=sql("SELECT sql FROM sqlite_master WHERE name = 'cw_CWAttribute'")[0][0]create=re.sub('cw_defaultval varchar[^,]*,','cw_defaultval bytea,',create,re.I)create=re.sub('cw_CWAttribute','tmp_cw_CWAttribute',create,re.I)sql(create)sql("INSERT INTO tmp_cw_CWAttribute SELECT * FROM cw_CWAttribute")forcwattrinrql('CWAttribute X').entities():olddefault=cwattr.defaultvalifolddefaultisNone:continuereq="UPDATE tmp_cw_CWAttribute SET cw_defaultval = %(val)s WHERE cw_eid = %(eid)s"args={'val':dbh.binary_value(convert_defaultval(cwattr,olddefault).getvalue()),'eid':cwattr.eid}sql(req,args,ask_confirm=False)sql('DROP TABLE cw_CWAttribute')sql('ALTER TABLE tmp_cw_CWAttribute RENAME TO cw_CWAttribute')else:assertFalse,'upgrade not supported on this database backend'# Set object type to "Bytes" for CWAttribute's "defaultval" attributerql('SET X to_entity B WHERE X is CWAttribute, X from_entity Y, Y name "CWAttribute", ''X relation_type Z, Z name "defaultval", B name "Bytes"')fromyamsimportbuildobjsasyboschema.add_relation_def(ybo.RelationDefinition('CWAttribute','defaultval','Bytes'))schema.del_relation_def('CWAttribute','defaultval','String')commit()forrschemainschema.relations():ifrschema.symmetric:withsession.allow_all_hooks_but('activeintegrity'):rql('SET X %(r)s Y WHERE Y %(r)s X, NOT X %(r)s Y'%{'r':rschema.type})commit()