dsn

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 22, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package dsn meant to work with Delivery Status Notification (DSN) per rfc3464: https://datatracker.ietf.org/doc/html/rfc3464

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsFailed

func IsFailed(n textproto.MIMEHeader) bool

IsFailed returns true if Action field is "failed", meaning message could not be delivered to the recipient.

Types

type DeliveryStatus

type DeliveryStatus struct {
	// RecipientDSN is Delivery Status Notification per message.
	MessageDSNs []textproto.MIMEHeader
	// RecipientDSN is Delivery Status Notification per recipient.
	RecipientDSNs []textproto.MIMEHeader
}

DeliveryStatus provides a machine-readable description of the condition(s) that caused the report to be generated.

type Explanation

type Explanation struct {
	// Text is a text/plain part of the explanation.
	Text string
	// HTML is a text/html part of the explanation.
	HTML string
}

Explanation contains a human-readable description of the condition(s) that caused the report to be generated. Where a description of the error is desired in several languages or several media, a multipart/alternative construct MAY be used.

type Report

type Report struct {
	// Explanation contains a human-readable description of the condition(s) that caused the report to be generated.
	Explanation Explanation
	// DeliveryStatus provides a machine-readable description of the condition(s) that caused the report to be generated.
	DeliveryStatus DeliveryStatus
	// OriginalMessage is optional original message or its portion.
	OriginalMessage []byte
}

Report represents delivery status report as per https://datatracker.ietf.org/doc/html/rfc6522. It is container of the MIME type multipart/report and contains 3 parts.

func ParseReport

func ParseReport(p *enmime.Part) (*Report, error)

ParseReport parses p as a "container" for delivery status report (per rfc6522) if p is "multipart/report". Otherwise returns nil.

Example

ExampleParseReport shows how to parse message as Delivery Status Notification (DSN).

package main

import (
	"fmt"
	"os"

	enmime "github.com/AntonSeregin/enmimebuilder"
	"github.com/AntonSeregin/enmimebuilder/dsn"
)

func main() {
	f, err := os.Open("testdata/simple_dsn.raw")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer f.Close()

	env, err := enmime.ReadEnvelope(f)
	if err != nil {
		fmt.Print(err)
		return
	}

	rep, err := dsn.ParseReport(env.Root)
	if err != nil {
		fmt.Print(err)
		return
	}

	fmt.Printf("Original message: %s", rep.OriginalMessage)
	fmt.Printf("Failed?: %t\n", dsn.IsFailed(rep.DeliveryStatus.RecipientDSNs[0]))
	fmt.Printf("Why?: %s", rep.Explanation.Text)
}
Output:

Original message: [original message goes here]
Failed?: true
Why?: [human-readable explanation goes here]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL