- add *.log to svn:ignore
- move mail function to gpgmail module - add parameter x-action=pgp-encrypted to mails git-svn-id: file:///home/www/usr01/svn/gnuviechadmin/gnuviech.info/gnuviechadmin/trunk@235 a67ec6bc-e5d5-0310-a910-815c51eb3124
This commit is contained in:
parent
732bb17fc5
commit
d46d04567d
2 changed files with 78 additions and 45 deletions
|
@ -19,13 +19,11 @@
|
|||
#
|
||||
# Version: $Id$
|
||||
|
||||
import smtplib, os, logging, tempfile
|
||||
from email.MIMEText import MIMEText
|
||||
from pyme import core
|
||||
from pyme.constants.sig import mode
|
||||
import os, logging, tempfile
|
||||
|
||||
from settings import config
|
||||
from gnuviechadmin.exceptions import *
|
||||
from gnuviechadmin.util import gpgmail
|
||||
from subprocess import *
|
||||
import sqlalchemy
|
||||
|
||||
|
@ -70,47 +68,7 @@ class BackendEntity(object):
|
|||
"""This method sends a mail with the given text and subject
|
||||
and signs it usign GnuPG. If a public key of the recipient is
|
||||
available the mail is encrypted."""
|
||||
plain = core.Data(text)
|
||||
cipher = core.Data()
|
||||
c = core.Context()
|
||||
c.set_armor(1)
|
||||
signer = config.get('common', 'mailfrom')
|
||||
rcpt = config.get('common', 'mailto')
|
||||
c.signers_clear()
|
||||
for sigkey in [x for x in c.op_keylist_all(signer, 1)]:
|
||||
if sigkey.can_sign:
|
||||
c.signers_add(sigkey)
|
||||
if not c.signers_enum(0):
|
||||
raise Exception("No secret keys for signing available for %s." % (
|
||||
signer))
|
||||
keylist = []
|
||||
for key in c.op_keylist_all(rcpt, 0):
|
||||
valid = 0
|
||||
subkey = key.subkeys
|
||||
while subkey:
|
||||
keyid = subkey.keyid
|
||||
if keyid == None:
|
||||
break
|
||||
can_encrypt = subkey.can_encrypt
|
||||
valid += can_encrypt
|
||||
subkey = subkey.next
|
||||
if valid:
|
||||
keylist.append(key)
|
||||
if keylist:
|
||||
c.op_encrypt_sign(keylist, 1, plain, cipher)
|
||||
else:
|
||||
c.op_sign(plain, cipher, mode.CLEAR)
|
||||
cipher.seek(0,0)
|
||||
|
||||
msg = MIMEText(cipher.read())
|
||||
msg['Subject'] = subject
|
||||
msg['From'] = signer
|
||||
msg['To'] = rcpt
|
||||
|
||||
s = smtplib.SMTP()
|
||||
s.connect()
|
||||
s.sendmail(signer, [rcpt], msg.as_string())
|
||||
s.close()
|
||||
gpgmail.send_mail(subject, text)
|
||||
|
||||
def validate(self):
|
||||
"""Validates whether all mandatory fields of the entity have
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue