(r io.Reader)
| 100 | } |
| 101 | |
| 102 | func (s *session) Data(r io.Reader) error { |
| 103 | raw, err := io.ReadAll(r) |
| 104 | if err != nil { |
| 105 | return err |
| 106 | } |
| 107 | |
| 108 | parsed, attachments, err := parseEmail(raw, s.to) |
| 109 | if err != nil { |
| 110 | slog.Error("smtp: failed to parse email", "err", err) |
| 111 | return nil |
| 112 | } |
| 113 | |
| 114 | // Generate event UUID for attachment storage. |
| 115 | eventUUID := event.GenerateUUID() |
| 116 | |
| 117 | // Store attachments. |
| 118 | if s.backend.attachments != nil && len(attachments) > 0 { |
| 119 | for _, att := range attachments { |
| 120 | path := eventUUID + "/" + att.Filename |
| 121 | if err := s.backend.attachments.Store(path, att.content); err != nil { |
| 122 | slog.Error("smtp: failed to store attachment", "err", err) |
| 123 | continue |
| 124 | } |
| 125 | attUUID := event.GenerateUUID() |
| 126 | if s.backend.db != nil { |
| 127 | s.backend.db.Exec( |
| 128 | `INSERT INTO smtp_attachments (uuid, event_uuid, name, path, size, mime, content_id) VALUES (?, ?, ?, ?, ?, ?, ?)`, |
| 129 | attUUID, eventUUID, att.Filename, path, len(att.content), att.Type, att.ContentID, |
| 130 | ) |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | payload, _ := json.Marshal(parsed) |
| 136 | |
| 137 | inc := &event.Incoming{ |
| 138 | UUID: eventUUID, |
| 139 | Type: "smtp", |
| 140 | Payload: json.RawMessage(payload), |
| 141 | Project: s.project, |
| 142 | } |
| 143 | |
| 144 | if err := s.backend.eventService.HandleIncoming(context.Background(), inc); err != nil { |
| 145 | slog.Error("smtp: failed to store event", "err", err) |
| 146 | } |
| 147 | return nil |
| 148 | } |
| 149 | |
| 150 | func (s *session) Reset() { s.from = ""; s.to = nil; s.project = "" } |
| 151 | func (s *session) Logout() error { return nil } |
nothing calls this directly
no test coverage detected