def get_addresses(dbinfo): """ Retrieve the notification email address from the database :param dbinfo: connection information :type dbinfo: dict :return: list of recipients and the sender address """ recieve = get_email_addr(dbinfo, 'cred_notification') sender = get_email_addr(dbinfo, 'espa_address') return recieve, sender
def sign_message(body, fromaddr, package='x', pgp_addr=None, sign='gpg', draftpath=None): '''Sign message with pgp key.''' ''' Return: a signed body. On failure, return None. kw need to have the following keys ''' if not pgp_addr: pgp_addr = get_email_addr(fromaddr)[1] # Make the unsigned file first (unsigned, file1) = TempFile(prefix=tempfile_prefix(package, 'unsigned'), dir=draftpath) unsigned.write(body) unsigned.close() # Now make the signed file (signed, file2) = TempFile(prefix=tempfile_prefix(package, 'signed'), dir=draftpath) signed.close() if sign == 'gpg': os.unlink(file2) if 'GPG_AGENT_INFO' not in os.environ: signcmd = "gpg --local-user '%s' --clearsign " % pgp_addr else: signcmd = "gpg --local-user '%s' --use-agent --clearsign " % pgp_addr signcmd += '--output ' + commands.mkarg(file2) + ' ' + commands.mkarg( file1) else: signcmd = "pgp -u '%s' -fast" % pgp_addr signcmd += '<' + commands.mkarg(file1) + ' >' + commands.mkarg(file2) try: os.system(signcmd) x = file(file2, 'r') signedbody = x.read() x.close() if os.path.exists(file1): os.unlink(file1) if os.path.exists(file2): os.unlink(file2) if not signedbody: raise NoMessage body = signedbody except (NoMessage, IOError, OSError): fh, tmpfile2 = TempFile(prefix=tempfile_prefix(package), dir=draftpath) fh.write(body) fh.close() ewrite('gpg/pgp failed; input file in %s\n', tmpfile2) body = None return body
def sign_message(body, fromaddr, package='x', pgp_addr=None, sign='gpg', draftpath=None): '''Sign message with pgp key.''' ''' Return: a signed body. On failure, return None. kw need to have the following keys ''' if not pgp_addr: pgp_addr = get_email_addr(fromaddr)[1] # Make the unsigned file first (unsigned, file1) = TempFile(prefix=tempfile_prefix(package, 'unsigned'), dir=draftpath) unsigned.write(body) unsigned.close() # Now make the signed file (signed, file2) = TempFile(prefix=tempfile_prefix(package, 'signed'), dir=draftpath) signed.close() if sign == 'gpg': os.unlink(file2) if 'GPG_AGENT_INFO' not in os.environ: signcmd = "gpg --local-user '%s' --clearsign " % pgp_addr else: signcmd = "gpg --local-user '%s' --use-agent --clearsign " % pgp_addr signcmd += '--output '+commands.mkarg(file2)+ ' ' + commands.mkarg(file1) else: signcmd = "pgp -u '%s' -fast" % pgp_addr signcmd += '<'+commands.mkarg(file1)+' >'+commands.mkarg(file2) try: os.system(signcmd) x = file(file2, 'r') signedbody = x.read() x.close() if os.path.exists(file1): os.unlink(file1) if os.path.exists(file2): os.unlink(file2) if not signedbody: raise NoMessage body = signedbody except (NoMessage, IOError, OSError): fh, tmpfile2 = TempFile(prefix=tempfile_prefix(package), dir=draftpath) fh.write(body) fh.close() ewrite('gpg/pgp failed; input file in %s\n', tmpfile2) body = None return body