def getValue(self, REQUEST):
        """ get the current value for this field from the request """
        if REQUEST is None:
            return None

        value = REQUEST.get(self.getId())
        if not value:
            return value

        if value == ENCRYPTED_VALUE_MARKER:
            return None

        keyid = getattr(self, 'gpg_keyid')
        value = gpg.encrypt(value, keyid)
        if not value.strip():
            # encryption failed
            raise EncryptionError('Encryption failed.')

        return value
    def get_mail_body(self, fields, **kwargs):
        """Returns the mail-body with footer.
        """

        bodyfield = self.getField('body_pt')
        
        # pass both the bare_fields (fgFields only) and full fields.
        # bare_fields for compatability with older templates,
        # full fields to enable access to htmlValue
        body = bodyfield.get(self, formFields=fields, **kwargs)

        if isinstance(body, unicode):
            body = body.encode(self.getCharset())

        keyid = getattr(self, 'gpg_keyid', None)
        encryption = gpg and keyid

        if encryption:
            bodygpg = gpg.encrypt(body, keyid)
            if bodygpg.strip():
                body = bodygpg

        return body
Esempio n. 3
0
    def encrypt(self, data, recipient_key_id):
        "Encrypt the message contained in the string 'data'"

        return gpg.encrypt(data, recipient_key_id)