func processSigned(m *pgpmail.Message, result *ProcessIncomingResult) error { status := m.Verify(keymgr.KeySource()) result.VerifyResult = status.Code if status.Code == pgpmail.VerifyFailed { result.FailureMessage = status.FailureMessage } if status.SignerKeyId != 0 { result.SignerKeyId = encodeKeyId(status.SignerKeyId) } return nil }
func getContentType(m *pgpmail.Message) string { ct := m.GetHeaderValue("Content-Type") if ct == "" { return "" } mt, _, err := mime.ParseMediaType(ct) if err != nil { return "" } return strings.ToLower(mt) }
func processEncrypted(m *pgpmail.Message, result *ProcessIncomingResult, passphrase []byte) error { status := m.DecryptWith(keymgr.KeySource(), passphrase) result.DecryptResult = status.Code result.VerifyResult = status.VerifyStatus.Code if status.Code == pgpmail.DecryptFailed { result.FailureMessage = status.FailureMessage } else if status.VerifyStatus.Code == pgpmail.VerifyFailed { result.FailureMessage = status.VerifyStatus.FailureMessage } if status.Code == pgpmail.DecryptPassphraseNeeded && status.KeyIds != nil { for _, id := range status.KeyIds { result.EncryptedKeyIds = append(result.EncryptedKeyIds, encodeKeyId(id)) } } if status.Code == pgpmail.DecryptSuccess { result.EmailBody = m.String() } return nil }
func createResponse(config *Config, data *verifyData) (string, error) { m := new(pgpmail.Message) m.AddHeader("From", config.VerifyEmail) m.AddHeader("To", data.sender.String()) m.AddHeader("Subject", "Nyms Mail Verification") m.AddHeader("X-Nyms-Verifier", "response") m.AddMultipart(createBody()) attach, err := createAttachment(data) if err != nil { return "", err } m.AddMultipart(attach) m.PackMultiparts() status := m.Sign(config.KeySource, "") if status.Code != pgpmail.StatusSignedOnly { return "", fmt.Errorf("signing message failed with status code %d: %s", status.Code, status.FailureMessage) } response := m.String() signed, err := dkimSign(config, response) if err != nil { logger.Warning("dkim signing failed: %v", err) return response, nil } return signed, nil }