Add methods to retrieve message ID and message from SendError

Implement MessageID and Msg methods in SendError to allow retrieval of the message ID and the affected message, respectively. These methods handle cases where the error or the message is nil, returning an empty string or nil as appropriate.
This commit is contained in:
Winni Neessen 2024-09-20 15:05:26 +02:00
parent fbebcf96d8
commit 0aa24c6f3a
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -118,6 +118,23 @@ func (e *SendError) IsTemp() bool {
return e.isTemp
}
// MessageID returns the message ID of the affected Msg that caused the error
// If no message ID was set for the Msg, an empty string will be returned
func (e *SendError) MessageID() string {
if e == nil || e.affectedMsg == nil {
return ""
}
return e.affectedMsg.GetMessageID()
}
// Msg returns the pointer to the affected message that caused the error
func (e *SendError) Msg() *Msg {
if e == nil || e.affectedMsg == nil {
return nil
}
return e.affectedMsg
}
// String implements the Stringer interface for the SendErrReason
func (r SendErrReason) String() string {
switch r {