|
| 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 | +}; |
0 commit comments