+def masked_email_from_str(value, mask='(at)', masked_only=False):
+ """Converts an email address that is possibly masked. Returns a tuple. The first parameter is the un-masked
+ email address as string, the second is a boolean telling whether the address was masked."""
+ unmasked = value.replace(mask, '@')
+ was_masked = unmasked != value
+ if masked_only and not was_masked:
+ raise ValueError('E-Mail address not masked')
+ return email_from_str(unmasked), was_masked
+
+
+def masked_email_to_str(value, mask='(at)'):
+ """Value is a tuple. The first entry is the email address, the second one is a boolean telling whether the
+ email address should be masked."""
+ email, do_masking = value
+ email = email_to_str(email)
+ if do_masking:
+ email = email.replace('@', mask)
+ return email
+