-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added Apple Push Notifications for IMAP iOS PUSH via XAPPLEPUSH…
…SERVICE (per <nodemailer/wildduck#711>)
- Loading branch information
Showing
26 changed files
with
172 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Copyright (c) Forward Email LLC | ||
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
const Aliases = require('#models/aliases'); | ||
|
||
const refineAndLogError = require('#helpers/refine-and-log-error'); | ||
|
||
// <https://github.com/nodemailer/wildduck/issues/711> | ||
// eslint-disable-next-line max-params | ||
async function onXAPPLEPUSHSERVICE( | ||
accountID, | ||
deviceToken, | ||
subTopic, | ||
mailboxes, | ||
session, | ||
fn | ||
) { | ||
this.logger.debug('XAPPLEPUSHSERVICE', { | ||
accountID, | ||
deviceToken, | ||
subTopic, | ||
mailboxes, | ||
session | ||
}); | ||
try { | ||
await this.refreshSession(session, 'XAPPLEPUSHSERVICE'); | ||
// update the alias with the provided data | ||
await Aliases.findByIdAndUpdate(session.user.alias_id, { | ||
$set: { | ||
aps_account_id: accountID, | ||
aps_device_token: deviceToken, | ||
aps_subtopic: subTopic, | ||
aps_mailboxes: mailboxes | ||
} | ||
}); | ||
fn(); | ||
} catch (err) { | ||
fn(refineAndLogError(err, session, true, this)); | ||
} | ||
} | ||
|
||
module.exports = onXAPPLEPUSHSERVICE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright (c) Forward Email LLC | ||
* SPDX-License-Identifier: BUSL-1.1 | ||
*/ | ||
|
||
const apn = require('@parse/node-apn'); | ||
const dayjs = require('dayjs-with-plugins'); | ||
|
||
const Aliases = require('#models/aliases'); | ||
const config = require('#config'); | ||
const env = require('#config/env'); | ||
const logger = require('#helpers/logger'); | ||
|
||
const apnProvider = new apn.Provider({ | ||
token: { | ||
key: env.APPLE_KEY_PATH, | ||
keyId: env.APPLE_KEY_ID, | ||
teamId: env.APPLE_TEAM_ID | ||
}, | ||
production: config.env === 'production' | ||
}); | ||
|
||
// <https://github.com/nodemailer/wildduck/issues/711> | ||
async function sendApn(id) { | ||
const alias = await Aliases.findOne({ | ||
id, | ||
aps_account_id: { $exists: true }, | ||
aps_device_token: { $exists: true } | ||
}) | ||
.lean() | ||
.select('+aps_account_id +aps_device_doken') | ||
.exec(); | ||
|
||
if (!alias) return; | ||
|
||
const note = new apn.Notification(); | ||
note.topic = 'com.apple.mobilemail'; | ||
note.expiry = dayjs().add(1, 'day').toDate().getTime(); | ||
note.payload = { | ||
'account-id': alias.aps_account_id | ||
}; | ||
|
||
logger.debug('note', note); | ||
|
||
// note they have commented out code at this below link for setting priority in note | ||
// <https://github.com/freswa/dovecot-xaps-daemon/blob/abce2f14cf1b5afa56329ebb4d923c9c2aebdfe3/internal/apns.go#L162-L163> | ||
|
||
const result = await apnProvider.send(note, alias.aps_device_token); | ||
logger.debug('apnProvider.send', { result }); | ||
} | ||
|
||
module.exports = sendApn; |
Oops, something went wrong.