2016-01-19 07:57:55 +08:00
|
|
|
import AdminUser from 'admin/models/admin-user';
|
|
|
|
|
|
|
|
const IncomingEmail = Discourse.Model.extend({});
|
|
|
|
|
|
|
|
IncomingEmail.reopenClass({
|
|
|
|
|
|
|
|
create(attrs) {
|
|
|
|
attrs = attrs || {};
|
|
|
|
|
|
|
|
if (attrs.user) {
|
|
|
|
attrs.user = AdminUser.create(attrs.user);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._super(attrs);
|
|
|
|
},
|
|
|
|
|
2016-02-11 05:00:27 +08:00
|
|
|
find(id) {
|
|
|
|
return Discourse.ajax(`/admin/email/incoming/${id}.json`);
|
|
|
|
},
|
|
|
|
|
2016-01-19 07:57:55 +08:00
|
|
|
findAll(filter, offset) {
|
|
|
|
filter = filter || {};
|
|
|
|
offset = offset || 0;
|
|
|
|
|
|
|
|
const status = filter.status || "received";
|
|
|
|
filter = _.omit(filter, "status");
|
|
|
|
|
|
|
|
return Discourse.ajax(`/admin/email/${status}.json?offset=${offset}`, { data: filter })
|
|
|
|
.then(incomings => _.map(incomings, incoming => IncomingEmail.create(incoming)));
|
2016-02-02 04:41:49 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
loadRawEmail(id) {
|
|
|
|
return Discourse.ajax(`/admin/email/incoming/${id}/raw.json`);
|
2016-01-19 07:57:55 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default IncomingEmail;
|