Skip to content

Commit f53d593

Browse files
committed
feat: added XAPPLEPUSHSERVICE support (per #711)
1 parent a68725d commit f53d593

File tree

4 files changed

+123
-1
lines changed

4 files changed

+123
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
'use strict';
2+
3+
//
4+
// Thanks to Forward Email
5+
// <https://forwardemail.net>
6+
// <https://github.com/nodemailer/wildduck/issues/711>
7+
// tag XAPPLEPUSHSERVICE aps-version 2 aps-account-id 0715A26B-CA09-4730-A419-793000CA982E aps-device-token 2918390218931890821908309283098109381029309829018310983092892829 aps-subtopic com.apple.mobilemail mailboxes (INBOX Notes)
8+
//
9+
10+
module.exports = {
11+
state: ['Authenticated', 'Selected'],
12+
13+
schema: [
14+
{
15+
name: 'aps-version',
16+
type: 'number' // always 2
17+
},
18+
{
19+
name: 'aps-account-id',
20+
type: 'string'
21+
},
22+
{
23+
name: 'aps-device-token',
24+
type: 'string'
25+
},
26+
{
27+
name: 'aps-subtopic',
28+
type: 'string' // always "com.apple.mobilemail"
29+
},
30+
// NOTE: this is irrelevant as it won't be used until we figure out how to notify for other than INBOX
31+
// <https://github.com/nodemailer/wildduck/issues/711#issuecomment-2251643672>
32+
{
33+
name: 'mailboxes',
34+
type: 'string' // e.g. (INBOX Notes)
35+
}
36+
],
37+
38+
handler(command, callback) {
39+
const version = Buffer.from((command.attributes[0] && command.attributes[0].value) || '', 'binary').toString();
40+
if (version !== "2")
41+
return callback(null, {
42+
response: 'NO',
43+
code: 'CLIENTBUG'
44+
});
45+
46+
const accountID = Buffer.from((command.attributes[1] && command.attributes[1].value) || '', 'binary').toString();
47+
const deviceToken = Buffer.from((command.attributes[2] && command.attributes[2].value) || '', 'binary').toString();
48+
const subTopic = Buffer.from((command.attributes[3] && command.attributes[3].value) || '', 'binary').toString();
49+
50+
if (subTopic !== "com.apple.mobilemail")
51+
return callback(null, {
52+
response: 'NO',
53+
code: 'CLIENTBUG'
54+
});
55+
56+
// NOTE: mailboxes param is not used at this time (it's a list anyways too)
57+
const mailboxes = Buffer.from((command.attributes[4] && command.attributes[4].value) || '', 'binary').toString();
58+
59+
if (typeof this._server.onXAPPLEPUSHSERVICE !== 'function') {
60+
return callback(null, {
61+
response: 'NO',
62+
message: command.command + ' not implemented'
63+
});
64+
}
65+
66+
let logdata = {
67+
short_message: '[XAPPLEPUSHSERVICE]',
68+
_mail_action: 'xapplepushservice',
69+
_accountId: accountID,
70+
_deviceToken: deviceToken,
71+
_subTopic: subTopic,
72+
_mailboxes: mailboxes,
73+
_user: this.session.user.id.toString(),
74+
_sess: this.id
75+
};
76+
77+
this._server.onXAPPLEPUSHSERVICE(accountID, deviceToken, subTopic, mailboxes, this.session, (err) => {
78+
if (err) {
79+
logdata._error = err.message;
80+
logdata._code = err.code;
81+
logdata._response = err.response;
82+
this._server.loggelf(logdata);
83+
84+
return callback(null, {
85+
response: 'NO',
86+
code: 'TEMPFAIL'
87+
});
88+
}
89+
90+
callback(null, {
91+
response: 'OK',
92+
message: 'Success'
93+
});
94+
});
95+
}
96+
};

imap-core/lib/imap-command.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ const commands = new Map([
4949
['GETQUOTAROOT', require('./commands/getquotaroot')],
5050
['SETQUOTA', require('./commands/setquota')],
5151
['GETQUOTA', require('./commands/getquota')],
52-
['COMPRESS', require('./commands/compress')]
52+
['COMPRESS', require('./commands/compress')],
53+
['XAPPLEPUSHSERVICE', require('./commands/xapplepushservice')]
5354
/*eslint-enable global-require*/
5455
]);
5556

imap.js

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const onMove = require('./lib/handlers/on-move');
3636
const onSearch = require('./lib/handlers/on-search');
3737
const onGetQuotaRoot = require('./lib/handlers/on-get-quota-root');
3838
const onGetQuota = require('./lib/handlers/on-get-quota');
39+
// const onXAPPLEPUSHSERVICE = require('./lib/handlers/on-xapplepushservice');
3940

4041
let logger = {
4142
info(...args) {
@@ -156,6 +157,7 @@ let createInterface = (ifaceOptions, callback) => {
156157
server.onSearch = onSearch(server);
157158
server.onGetQuotaRoot = onGetQuotaRoot(server);
158159
server.onGetQuota = onGetQuota(server);
160+
// server.onXAPPLEPUSHSERVICE = onXAPPLEPUSHSERVICE(server);
159161

160162
if (loggelf) {
161163
server.loggelf = loggelf;

lib/handlers/on-xapplepushservice.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
//
4+
// Thanks to Forward Email
5+
// <https://forwardemail.net>
6+
// <https://github.com/nodemailer/wildduck/issues/711>
7+
// tag XAPPLEPUSHSERVICE aps-version 2 aps-account-id 0715A26B-CA09-4730-A419-793000CA982E aps-device-token 2918390218931890821908309283098109381029309829018310983092892829 aps-subtopic com.apple.mobilemail mailboxes (INBOX Notes)
8+
//
9+
module.exports = server => (accountID, deviceToken, subTopic, mailboxes, session, callback) => {
10+
server.logger.debug(
11+
{
12+
tnx: 'xapplepushservice',
13+
cid: session.id
14+
},
15+
'[%s] XAPPLEPUSHSERVICE accountID "%s" deviceToken "%s" subTopic "%s" mailboxes "%s"',
16+
session.id,
17+
accountID,
18+
deviceToken,
19+
subTopic,
20+
mailboxes
21+
);
22+
return callback(new Error('Not implemented, see <https://github.com/nodemailer/wildduck/issues/711>'));
23+
};

0 commit comments

Comments
 (0)