mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-09-06 21:24:37 +08:00
Updated XAPPLEPUSHSERVICE schema handling
This commit is contained in:
parent
4e96db26ad
commit
4ef3eaabca
5 changed files with 178 additions and 128 deletions
|
@ -54,6 +54,11 @@ ignoredHosts = []
|
|||
#secure=false
|
||||
#ignoreSTARTTLS=true
|
||||
|
||||
# Apple push notificiations
|
||||
# TODO: missing actual implementation for Apple Push Service
|
||||
[aps]
|
||||
enabled = false
|
||||
|
||||
[setup]
|
||||
# Public configuration for IMAP
|
||||
hostname = "localhost"
|
||||
|
|
|
@ -7,37 +7,14 @@
|
|||
// 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)
|
||||
//
|
||||
|
||||
const requiredKeys = ['aps-version', 'aps-account-id', 'aps-device-token', 'aps-subtopic', 'mailboxes'];
|
||||
|
||||
module.exports = {
|
||||
state: ['Authenticated', 'Selected'],
|
||||
|
||||
/*
|
||||
Schema: [
|
||||
{
|
||||
name: 'aps-version',
|
||||
type: 'number' // always 2
|
||||
},
|
||||
{
|
||||
name: 'aps-account-id',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
name: 'aps-device-token',
|
||||
type: 'string'
|
||||
},
|
||||
{
|
||||
name: 'aps-subtopic',
|
||||
type: 'string' // always "com.apple.mobilemail"
|
||||
},
|
||||
// NOTE: this is irrelevant as it won't be used until we figure out how to notify for other than INBOX
|
||||
// <https://github.com/nodemailer/wildduck/issues/711#issuecomment-2251643672>
|
||||
{
|
||||
name: 'mailboxes',
|
||||
type: 'string' // e.g. (INBOX Notes)
|
||||
}
|
||||
],
|
||||
*/
|
||||
// the input is a key-value set which is not supported by the default schema handler
|
||||
schema: false,
|
||||
|
||||
// it's actually something like this in production
|
||||
// [
|
||||
// { type: 'ATOM', value: 'aps-version' },
|
||||
// { type: 'ATOM', value: '2' },
|
||||
|
@ -57,9 +34,6 @@ module.exports = {
|
|||
// ]
|
||||
// ]
|
||||
|
||||
// disabled for now
|
||||
schema: false,
|
||||
|
||||
handler(command, callback) {
|
||||
// Command = {
|
||||
// tag: 'I5',
|
||||
|
@ -84,32 +58,93 @@ module.exports = {
|
|||
// ]
|
||||
// }
|
||||
|
||||
const version = (command.attributes[1] && command.attributes[1].value) || '';
|
||||
if (version !== '2') {
|
||||
const apsConfig = this._server.options.aps || {};
|
||||
|
||||
// Reject if not enabled
|
||||
if (!apsConfig.enabled) {
|
||||
return callback(null, {
|
||||
response: 'NO',
|
||||
code: 'CLIENTBUG',
|
||||
response: 'BAD',
|
||||
message: `Unknown command: ${command.command}`
|
||||
});
|
||||
}
|
||||
|
||||
const accountID = (command.attributes[3] && command.attributes[3].value) || '';
|
||||
const deviceToken = (command.attributes[5] && command.attributes[5].value) || '';
|
||||
const subTopic = (command.attributes[7] && command.attributes[7].value) || '';
|
||||
// Parse input arguments into a structured object:
|
||||
|
||||
// {
|
||||
// "aps-version": "2",
|
||||
// "aps-account-id": "0715A26B-CA09-4730-A419-793000CA982E",
|
||||
// "aps-device-token": "2918390218931890821908309283098109381029309829018310983092892829",
|
||||
// "aps-subtopic": "com.apple.mobilemail",
|
||||
// "mailboxes": [
|
||||
// "INBOX",
|
||||
// "Notes"
|
||||
// ]
|
||||
// }
|
||||
|
||||
let data = {};
|
||||
let keyName;
|
||||
for (let i = 0, len = (command.attributes || []).length; i < len; i++) {
|
||||
let isKey = i % 2 === 0;
|
||||
let attr = command.attributes[i];
|
||||
if (isKey && !['ATOM', 'STRING'].includes(attr.type)) {
|
||||
return callback(null, {
|
||||
response: 'BAD',
|
||||
message: `Invalid argument for ${command.command}`
|
||||
});
|
||||
}
|
||||
if (isKey) {
|
||||
keyName = (attr.value || '').toString().toLowerCase();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!requiredKeys.includes(keyName)) {
|
||||
// skip unknown keys
|
||||
}
|
||||
|
||||
if (['ATOM', 'STRING'].includes(attr.type)) {
|
||||
data[keyName] = (attr.value || '').toString();
|
||||
} else if (Array.isArray(attr) && keyName === 'mailboxes') {
|
||||
let mailboxes = attr
|
||||
.map(entry => {
|
||||
if (['ATOM', 'STRING'].includes(entry.type)) {
|
||||
return (entry.value || '').toString();
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.filter(name => name);
|
||||
data[keyName] = mailboxes;
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure all required keys (exept mailboxes) are present
|
||||
for (let requiredKey of requiredKeys) {
|
||||
if (!data[requiredKey] && requiredKey !== 'mailboxes') {
|
||||
return callback(null, {
|
||||
response: 'BAD',
|
||||
message: `Missing required arguments for ${command.command}`
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const version = data['aps-version'];
|
||||
const accountID = data['aps-account-id'];
|
||||
const deviceToken = data['aps-device-token'];
|
||||
const subTopic = data['aps-subtopic'];
|
||||
const mailboxes = data.mailboxes || [];
|
||||
|
||||
if (version !== '2') {
|
||||
return callback(null, {
|
||||
response: 'NO',
|
||||
message: 'Unsupported APS version',
|
||||
code: 'CLIENTBUG'
|
||||
});
|
||||
}
|
||||
|
||||
if (subTopic !== 'com.apple.mobilemail') {
|
||||
return callback(null, {
|
||||
response: 'NO',
|
||||
code: 'CLIENTBUG',
|
||||
});
|
||||
}
|
||||
|
||||
// NOTE: mailboxes param is not used at this time (it's a list anyways too)
|
||||
const mailboxes = command.attributes[9] && Array.isArray(command.attributes[9]) && command.attributes[9].length > 0 ? command.attributes[9].map(object => object.value) : [];
|
||||
|
||||
if (typeof this._server.onXAPPLEPUSHSERVICE !== 'function') {
|
||||
return callback(null, {
|
||||
response: 'NO',
|
||||
message: command.command + ' not implemented',
|
||||
message: `Invalid subtopic for ${command.command}`,
|
||||
code: 'CLIENTBUG'
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -121,7 +156,7 @@ module.exports = {
|
|||
_subTopic: subTopic,
|
||||
_mailboxes: mailboxes,
|
||||
_user: this.session.user.id.toString(),
|
||||
_sess: this.id,
|
||||
_sess: this.id
|
||||
};
|
||||
|
||||
this._server.onXAPPLEPUSHSERVICE(accountID, deviceToken, subTopic, mailboxes, this.session, error => {
|
||||
|
@ -133,7 +168,7 @@ module.exports = {
|
|||
|
||||
return callback(null, {
|
||||
response: 'NO',
|
||||
code: 'TEMPFAIL',
|
||||
code: 'TEMPFAIL'
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -145,5 +180,5 @@ module.exports = {
|
|||
message: 'XAPPLEPUSHSERVICE Registration successful.'
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
|
|
|
@ -717,9 +717,6 @@ module.exports.getQueryResponse = function (query, message, options) {
|
|||
module.exports.sendCapabilityResponse = connection => {
|
||||
let capabilities = [];
|
||||
|
||||
if (typeof connection._server.onXAPPLEPUSHSERVICE === 'function')
|
||||
capabilities.push('XAPPLEPUSHSERVICE');
|
||||
|
||||
if (!connection.secure) {
|
||||
if (!connection._server.options.disableSTARTTLS) {
|
||||
capabilities.push('STARTTLS');
|
||||
|
@ -766,6 +763,10 @@ module.exports.sendCapabilityResponse = connection => {
|
|||
if (connection._server.options.maxMessage) {
|
||||
capabilities.push('APPENDLIMIT=' + connection._server.options.maxMessage);
|
||||
}
|
||||
|
||||
if (connection._server.options.aps?.enabled) {
|
||||
capabilities.push('XAPPLEPUSHSERVICE');
|
||||
}
|
||||
}
|
||||
|
||||
capabilities.sort((a, b) => a.localeCompare(b));
|
||||
|
|
6
imap.js
6
imap.js
|
@ -36,7 +36,7 @@ const onMove = require('./lib/handlers/on-move');
|
|||
const onSearch = require('./lib/handlers/on-search');
|
||||
const onGetQuotaRoot = require('./lib/handlers/on-get-quota-root');
|
||||
const onGetQuota = require('./lib/handlers/on-get-quota');
|
||||
// const onXAPPLEPUSHSERVICE = require('./lib/handlers/on-xapplepushservice');
|
||||
const onXAPPLEPUSHSERVICE = require('./lib/handlers/on-xapplepushservice');
|
||||
|
||||
let logger = {
|
||||
info(...args) {
|
||||
|
@ -78,6 +78,8 @@ let createInterface = (ifaceOptions, callback) => {
|
|||
vendor: config.imap.vendor || 'Kreata'
|
||||
},
|
||||
|
||||
aps: config.imap.aps,
|
||||
|
||||
logger,
|
||||
|
||||
maxMessage: config.imap.maxMB * 1024 * 1024,
|
||||
|
@ -157,7 +159,7 @@ let createInterface = (ifaceOptions, callback) => {
|
|||
server.onSearch = onSearch(server);
|
||||
server.onGetQuotaRoot = onGetQuotaRoot(server);
|
||||
server.onGetQuota = onGetQuota(server);
|
||||
// server.onXAPPLEPUSHSERVICE = onXAPPLEPUSHSERVICE(server);
|
||||
server.onXAPPLEPUSHSERVICE = onXAPPLEPUSHSERVICE(server);
|
||||
|
||||
if (loggelf) {
|
||||
server.loggelf = loggelf;
|
||||
|
|
|
@ -6,6 +6,12 @@
|
|||
// <https://github.com/nodemailer/wildduck/issues/711>
|
||||
// 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)
|
||||
//
|
||||
|
||||
// TODO:
|
||||
// 1. store APS information in DB, each deviceToken separately
|
||||
// 2. on new email use the stored information to push to apple (use mathcing deviceTokens as an array of recipients)
|
||||
// 3. if pushing to a specific deviceToken yields in 410, remove that token
|
||||
|
||||
module.exports = server => (accountID, deviceToken, subTopic, mailboxes, session, callback) => {
|
||||
server.logger.debug(
|
||||
{
|
||||
|
@ -19,5 +25,6 @@ module.exports = server => (accountID, deviceToken, subTopic, mailboxes, session
|
|||
subTopic,
|
||||
mailboxes
|
||||
);
|
||||
|
||||
return callback(new Error('Not implemented, see <https://github.com/nodemailer/wildduck/issues/711>'));
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue