예제 #1
0
func processOutgoingMail(body string, sign, encrypt bool, passphrase string, result *ProcessOutgoingResult) error {
	m, err := pgpmail.ParseMessage(body)
	if err != nil {
		return err
	}
	if !needsOutgoingProcessing(m) {
		return nil
	}

	if !encrypt {
		if sign {
			status := m.Sign(keymgr.KeySource(), passphrase)
			processOutgoingStatus(m, status, result)
			return nil
		}
		return nil
	}

	if sign {
		status := m.EncryptAndSign(keymgr.KeySource(), passphrase)
		processOutgoingStatus(m, status, result)
	} else {
		status := m.Encrypt(keymgr.KeySource())
		processOutgoingStatus(m, status, result)
	}
	return nil
}
예제 #2
0
func processIncomingMail(body string, result *ProcessIncomingResult, passphrase []byte) error {
	result.VerifyResult = pgpmail.VerifyNotSigned
	result.DecryptResult = pgpmail.DecryptNotEncrypted

	m, err := pgpmail.ParseMessage(body)
	if err != nil {
		return err
	}
	if !needsIncomingProcessing(m) {
		return nil
	}
	ct := getContentType(m)
	if ct == "multipart/encrypted" || isInlineEncrypted(m) {
		err = processEncrypted(m, result, passphrase)
		if err != nil {
			return err
		}
	}
	ct = getContentType(m)
	if ct == "multipart/signed" || isInlineSigned(m) {
		err = processSigned(m, result)
		if err != nil {
			return err
		}
	}
	return nil
}