send emails
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
package utils
|
||||
|
||||
// MTA is mail transfer agent
|
||||
type MTA interface {
|
||||
Send(from, to, data string) error
|
||||
}
|
||||
|
||||
// Email object
|
||||
type Email struct {
|
||||
MessageID string
|
||||
|
||||
@@ -26,6 +26,45 @@ func RelatesTo(noThreads bool, parentID id.EventID) *event.RelatesTo {
|
||||
}
|
||||
}
|
||||
|
||||
// EventParent returns parent event - either thread ID or reply-to ID
|
||||
func EventParent(currentID id.EventID, content *event.MessageEventContent) id.EventID {
|
||||
if content == nil {
|
||||
return currentID
|
||||
}
|
||||
|
||||
if content.GetRelatesTo() == nil {
|
||||
return currentID
|
||||
}
|
||||
|
||||
threadParent := content.RelatesTo.GetThreadParent()
|
||||
if threadParent != "" {
|
||||
return threadParent
|
||||
}
|
||||
|
||||
replyParent := content.RelatesTo.GetReplyTo()
|
||||
if replyParent != "" {
|
||||
return replyParent
|
||||
}
|
||||
|
||||
return currentID
|
||||
}
|
||||
|
||||
// EventField returns field value from raw event content
|
||||
func EventField[T comparable](content *event.Content, field string) T {
|
||||
var zero T
|
||||
raw := content.Raw[field]
|
||||
if raw == nil {
|
||||
return zero
|
||||
}
|
||||
|
||||
v, ok := raw.(T)
|
||||
if !ok {
|
||||
return zero
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
|
||||
// UnwrapError tries to unwrap a error into something meaningful, like mautrix.HTTPError or mautrix.RespError
|
||||
func UnwrapError(err error) error {
|
||||
switch err.(type) {
|
||||
|
||||
Reference in New Issue
Block a user