| 1 |
package smtp |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/nicholas-fedor/shoutrrr/internal/failures" |
| 5 |
) |
| 6 |
|
| 7 |
// failure is an interface for SMTP-specific errors, implementing failures.Failure |
| 8 |
// to provide detailed error messages and IDs for debugging within the shoutrrr framework. |
| 9 |
type failure interface { |
| 10 |
failures.Failure |
| 11 |
} |
| 12 |
|
| 13 |
const ( |
| 14 |
// FailUnknown is the default FailureID. |
| 15 |
FailUnknown failures.FailureID = iota |
| 16 |
// FailGetSMTPClient is returned when a SMTP client could not be created. |
| 17 |
FailGetSMTPClient |
| 18 |
// FailEnableStartTLS is returned when failing to enable StartTLS. |
| 19 |
FailEnableStartTLS |
| 20 |
// FailAuthType is returned when the Auth type could not be identified. |
| 21 |
FailAuthType |
| 22 |
// FailAuthenticating is returned when the authentication fails. |
| 23 |
FailAuthenticating |
| 24 |
// FailSendRecipient is returned when sending to a recipient fails. |
| 25 |
FailSendRecipient |
| 26 |
// FailClosingSession is returned when the server doesn't accept the QUIT command. |
| 27 |
FailClosingSession |
| 28 |
// FailPlainHeader is returned when the text/plain multipart header could not be set. |
| 29 |
FailPlainHeader |
| 30 |
// FailHTMLHeader is returned when the text/html multipart header could not be set. |
| 31 |
FailHTMLHeader |
| 32 |
// FailMultiEndHeader is returned when the multipart end header could not be set. |
| 33 |
FailMultiEndHeader |
| 34 |
// FailMessageTemplate is returned when the message template could not be written to the stream. |
| 35 |
FailMessageTemplate |
| 36 |
// FailMessageRaw is returned when a non-templated message could not be written to the stream. |
| 37 |
FailMessageRaw |
| 38 |
// FailSetSender is returned when the server didn't accept the sender address. |
| 39 |
FailSetSender |
| 40 |
// FailSetRecipient is returned when the server didn't accept the recipient address. |
| 41 |
FailSetRecipient |
| 42 |
// FailOpenDataStream is returned when the server didn't accept the data stream. |
| 43 |
FailOpenDataStream |
| 44 |
// FailWriteHeaders is returned when the headers could not be written to the data stream. |
| 45 |
FailWriteHeaders |
| 46 |
// FailCloseDataStream is returned when the server didn't accept the data stream contents. |
| 47 |
FailCloseDataStream |
| 48 |
// FailConnectToServer is returned when the TCP connection to the server failed. |
| 49 |
FailConnectToServer |
| 50 |
// FailCreateSMTPClient is returned when the smtp.Client initialization failed. |
| 51 |
FailCreateSMTPClient |
| 52 |
// FailApplySendParams is returned when updating the send config failed. |
| 53 |
FailApplySendParams |
| 54 |
// FailHandshake is returned when the initial HELLO handshake returned an error. |
| 55 |
FailHandshake |
| 56 |
) |
| 57 |
|
| 58 |
// fail creates an SMTP-specific failure with a descriptive message and ID, |
| 59 |
// wrapping the provided error and optional arguments for additional context. |
| 60 |
func fail(failureID failures.FailureID, err error, args ...any) failure { |
| 61 |
var msg string |
| 62 |
|
| 63 |
switch failureID { |
| 64 |
case FailGetSMTPClient: |
| 65 |
msg = "error getting SMTP client" |
| 66 |
case FailConnectToServer: |
| 67 |
msg = "error connecting to server" |
| 68 |
case FailCreateSMTPClient: |
| 69 |
msg = "error creating smtp client" |
| 70 |
case FailEnableStartTLS: |
| 71 |
msg = "error enabling StartTLS" |
| 72 |
case FailAuthenticating: |
| 73 |
msg = "error authenticating" |
| 74 |
case FailAuthType: |
| 75 |
msg = "invalid authorization method '%s'" |
| 76 |
case FailSendRecipient: |
| 77 |
msg = "error sending message to recipient %q" |
| 78 |
case FailClosingSession: |
| 79 |
msg = "error closing session" |
| 80 |
case FailPlainHeader: |
| 81 |
msg = "error writing plain header" |
| 82 |
case FailHTMLHeader: |
| 83 |
msg = "error writing HTML header" |
| 84 |
case FailMultiEndHeader: |
| 85 |
msg = "error writing multipart end header" |
| 86 |
case FailMessageTemplate: |
| 87 |
msg = "error applying message template" |
| 88 |
case FailMessageRaw: |
| 89 |
msg = "error writing message" |
| 90 |
case FailSetSender: |
| 91 |
msg = "error creating new message" |
| 92 |
case FailSetRecipient: |
| 93 |
msg = "error setting RCPT" |
| 94 |
case FailOpenDataStream: |
| 95 |
msg = "error creating message stream" |
| 96 |
case FailWriteHeaders: |
| 97 |
msg = "error writing message headers" |
| 98 |
case FailCloseDataStream: |
| 99 |
msg = "error closing message stream" |
| 100 |
case FailApplySendParams: |
| 101 |
msg = "error applying params to send config" |
| 102 |
case FailHandshake: |
| 103 |
msg = "server did not accept the handshake" |
| 104 |
// case FailUnknown: |
| 105 |
default: |
| 106 |
msg = "an unknown error occurred" |
| 107 |
} |
| 108 |
|
| 109 |
return failures.Wrap(msg, failureID, err, args...) |
| 110 |
} |