(dbResource *resource.DbResource, certificateManager *resource.CertificateManager)
| 158 | } |
| 159 | |
| 160 | func DaptinSmtpDbResource(dbResource *resource.DbResource, certificateManager *resource.CertificateManager) func() backends.Decorator { |
| 161 | |
| 162 | return func() backends.Decorator { |
| 163 | var config *SQLProcessorConfig |
| 164 | //var db *sql.DB |
| 165 | s := &SQLProcessor{} |
| 166 | |
| 167 | // open the database connection (it will also check if we can select the table) |
| 168 | backends.Svc.AddInitializer(backends.InitializeWith(func(backendConfig backends.BackendConfig) error { |
| 169 | configType := backends.BaseConfig(&SQLProcessorConfig{}) |
| 170 | bcfg, err := backends.Svc.ExtractConfig(backendConfig, configType) |
| 171 | if err != nil { |
| 172 | return err |
| 173 | } |
| 174 | config = bcfg.(*SQLProcessorConfig) |
| 175 | s.config = config |
| 176 | return nil |
| 177 | })) |
| 178 | |
| 179 | // shutdown will close the database connection |
| 180 | backends.Svc.AddShutdowner(backends.ShutdownWith(func() error { |
| 181 | //if db != nil { |
| 182 | // return db.Close() |
| 183 | //} |
| 184 | return nil |
| 185 | })) |
| 186 | |
| 187 | return func(p backends.Processor) backends.Processor { |
| 188 | mailSender := func(e *mail.Envelope, task backends.SelectTask) (backends.Result, error) { |
| 189 | |
| 190 | if task == backends.TaskSaveMail { |
| 191 | var to, body string |
| 192 | |
| 193 | hash := "" |
| 194 | if len(e.Hashes) > 0 { |
| 195 | hash = e.Hashes[0] |
| 196 | e.QueuedId = e.Hashes[0] |
| 197 | } |
| 198 | |
| 199 | //if c, ok := e.Values["zlib-compressor"]; ok { |
| 200 | // co = c.(Compressor) |
| 201 | //} |
| 202 | |
| 203 | for i := range e.RcptTo { |
| 204 | // use the To header, otherwise rcpt to |
| 205 | to = trimToLimit(s.fillAddressFromHeader(e, "To"), 255) |
| 206 | rcpt := e.RcptTo[i] |
| 207 | if to == "" { |
| 208 | // trimToLimit(strings.TrimSpace(e.RcptTo[i].User)+"@"+config.PrimaryHost, 255) |
| 209 | to = trimToLimit(strings.TrimSpace(rcpt.String()), 255) |
| 210 | } |
| 211 | mid := trimToLimit(s.fillAddressFromHeader(e, "Message-Id"), 255) |
| 212 | if mid == "" { |
| 213 | mid = fmt.Sprintf("%s.%s@%s", hash, rcpt.User, config.PrimaryHost) |
| 214 | } |
| 215 | // replyTo is the 'Reply-to' header, it may be blank |
| 216 | replyTo := trimToLimit(s.fillAddressFromHeader(e, "Reply-To"), 255) |
| 217 | // sender is the 'Sender' header, it may be blank |
no test coverage detected