2016-06-30 13:55:44 -04:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2016-01-18 18:57:55 -05:00
|
|
|
import AdminUser from "admin/models/admin-user";
|
2019-11-08 14:13:35 -05:00
|
|
|
import EmberObject from "@ember/object";
|
2016-01-18 18:57:55 -05:00
|
|
|
|
2019-11-08 14:13:35 -05:00
|
|
|
const IncomingEmail = EmberObject.extend({});
|
2016-01-18 18:57:55 -05:00
|
|
|
|
|
|
|
IncomingEmail.reopenClass({
|
|
|
|
create(attrs) {
|
|
|
|
attrs = attrs || {};
|
|
|
|
|
|
|
|
if (attrs.user) {
|
|
|
|
attrs.user = AdminUser.create(attrs.user);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._super(attrs);
|
|
|
|
},
|
|
|
|
|
2016-02-10 16:00:27 -05:00
|
|
|
find(id) {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax(`/admin/email/incoming/${id}.json`);
|
2016-02-10 16:00:27 -05:00
|
|
|
},
|
|
|
|
|
2017-02-22 12:51:33 -05:00
|
|
|
findByBounced(id) {
|
|
|
|
return ajax(`/admin/email/incoming_from_bounced/${id}.json`);
|
|
|
|
},
|
|
|
|
|
2016-01-18 18:57:55 -05:00
|
|
|
findAll(filter, offset) {
|
|
|
|
filter = filter || {};
|
|
|
|
offset = offset || 0;
|
|
|
|
|
|
|
|
const status = filter.status || "received";
|
2020-09-01 13:38:57 -04:00
|
|
|
delete filter.status;
|
2016-01-18 18:57:55 -05:00
|
|
|
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax(`/admin/email/${status}.json?offset=${offset}`, {
|
|
|
|
data: filter,
|
2016-01-18 18:57:55 -05:00
|
|
|
}).then((incomings) =>
|
2018-11-19 04:46:46 -05:00
|
|
|
incomings.map((incoming) => IncomingEmail.create(incoming))
|
2016-01-18 18:57:55 -05:00
|
|
|
);
|
2016-02-01 15:41:49 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
loadRawEmail(id) {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax(`/admin/email/incoming/${id}/raw.json`);
|
2016-01-18 18:57:55 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default IncomingEmail;
|