From ef118325bafb183380a7b81f82e088ff93dfc261 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Wed, 11 Jan 2023 09:47:07 -0700 Subject: [PATCH] Add intiial 'flavor' for ActivityPub messages --- core/mail_util.js | 15 +++++++++++++++ core/message.js | 1 + core/servers/content/web_handlers/activitypub.js | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/core/mail_util.js b/core/mail_util.js index 9b4bfefe..15a467ff 100644 --- a/core/mail_util.js +++ b/core/mail_util.js @@ -21,6 +21,7 @@ const EMAIL_REGEX = 43:20/100.2 { flavor : 'ftn', remote : '43:20/100.2' } foo@host.com { name : 'foo', flavor : 'email', remote : 'foo@host.com' } Bar { name : 'Bar', flavor : 'email', remote : 'baz@foobar.com' } + @JoeUser@some.host.com { name : 'Joe User', flavor : 'activitypub', remote 'JoeUser@some.host.com' } */ function getAddressedToInfo(input) { input = input.trim(); @@ -55,6 +56,20 @@ function getAddressedToInfo(input) { return { name: input, flavor: Message.AddressFlavor.Local }; } + if (firstAtPos === 0) { + const secondAtPos = input.indexOf('@', 1); + if (secondAtPos > 0) { + const m = input.slice(1).match(EMAIL_REGEX); + if (m) { + return { + name: input.slice(1, secondAtPos), + flavor: Message.AddressFlavor.ActivityPub, + remote: input.slice(firstAtPos), + }; + } + } + } + const lessThanPos = input.indexOf('<'); const greaterThanPos = input.indexOf('>'); if (lessThanPos > 0 && greaterThanPos > lessThanPos) { diff --git a/core/message.js b/core/message.js index 6a063802..47c16821 100644 --- a/core/message.js +++ b/core/message.js @@ -56,6 +56,7 @@ const ADDRESS_FLAVOR = { Email: 'email', // From email QWK: 'qwk', // QWK packet NNTP: 'nntp', // NNTP article POST; often a email address + ActivityPub: 'activitypub', // ActivityPub, Mastodon, etc. }; const STATE_FLAGS0 = { diff --git a/core/servers/content/web_handlers/activitypub.js b/core/servers/content/web_handlers/activitypub.js index de149707..45a57b07 100644 --- a/core/servers/content/web_handlers/activitypub.js +++ b/core/servers/content/web_handlers/activitypub.js @@ -229,6 +229,7 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule { return; } + // :TODO: This stuff should probably be lifted out so it can be called ad-hoc from the queue const accept = Activity.makeAccept( this.webServer, localActor, @@ -281,6 +282,11 @@ exports.getModule = class ActivityPubWebHandler extends WebHandlerModule { 'Unexpected status code' ); } + + this.log.trace( + { inbox: actor.inbox }, + 'Remote server received our "Accept" successfully' + ); } ); });