langmail-mcp 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +89 -169
  3. package/dist/chunk-ad2666h8.js +12696 -0
  4. package/dist/langmail-mcp.js +7 -0
  5. package/package.json +94 -98
  6. package/THIRD_PARTY_NOTICES.md +0 -388
  7. package/dist/attachments/download.js +0 -69
  8. package/dist/attachments/routes.js +0 -42
  9. package/dist/attachments/tickets.js +0 -45
  10. package/dist/attachments/upload-tickets.js +0 -43
  11. package/dist/attachments/upload.js +0 -136
  12. package/dist/caldav/account-settings.js +0 -92
  13. package/dist/caldav/agenda.js +0 -277
  14. package/dist/caldav/alarm.js +0 -97
  15. package/dist/caldav/client.js +0 -408
  16. package/dist/caldav/ical.js +0 -248
  17. package/dist/caldav/occurrence.js +0 -534
  18. package/dist/caldav/recurrence.js +0 -313
  19. package/dist/caldav/rsvp.js +0 -107
  20. package/dist/caldav/scheduling-handover.js +0 -22
  21. package/dist/caldav/timezone.js +0 -103
  22. package/dist/caldav/types.js +0 -5
  23. package/dist/config.js +0 -219
  24. package/dist/contacts/address-class.js +0 -79
  25. package/dist/contacts/birthdays.js +0 -81
  26. package/dist/contacts/card.js +0 -58
  27. package/dist/contacts/constants.js +0 -46
  28. package/dist/contacts/fold.js +0 -309
  29. package/dist/contacts/index.js +0 -10
  30. package/dist/contacts/merge.js +0 -388
  31. package/dist/contacts/observations.js +0 -115
  32. package/dist/contacts/profile.js +0 -402
  33. package/dist/contacts/scoring.js +0 -146
  34. package/dist/contacts/types.js +0 -7
  35. package/dist/contacts/upsert.js +0 -131
  36. package/dist/drafts/attachments.js +0 -254
  37. package/dist/drafts/idempotency.js +0 -60
  38. package/dist/drafts/send-guard.js +0 -184
  39. package/dist/email-render/email-viewer.html +0 -143
  40. package/dist/email-render/image-proxy.js +0 -389
  41. package/dist/email-render/meta.js +0 -48
  42. package/dist/email-render/sanitize.js +0 -93
  43. package/dist/email-render/viewer-resource.js +0 -104
  44. package/dist/http/bearer.js +0 -30
  45. package/dist/http/guard.js +0 -57
  46. package/dist/http/hosts.js +0 -10
  47. package/dist/http/listener.js +0 -170
  48. package/dist/http/routes.js +0 -72
  49. package/dist/ical/ical-parse.js +0 -357
  50. package/dist/ical/index.js +0 -4
  51. package/dist/ical/timezone.js +0 -22
  52. package/dist/ical/windows-zones.js +0 -155
  53. package/dist/index.js +0 -79
  54. package/dist/jmap/blob.js +0 -49
  55. package/dist/jmap/contacts.js +0 -226
  56. package/dist/jmap/drafts.js +0 -480
  57. package/dist/jmap/email.js +0 -668
  58. package/dist/jmap/index.js +0 -12
  59. package/dist/jmap/keywords.js +0 -22
  60. package/dist/jmap/live.js +0 -21
  61. package/dist/jmap/origin.js +0 -113
  62. package/dist/jmap/patch.js +0 -29
  63. package/dist/jmap/request.js +0 -37
  64. package/dist/jmap/session.js +0 -89
  65. package/dist/jmap/sieve.js +0 -71
  66. package/dist/jmap/submission.js +0 -107
  67. package/dist/jmap/timeout.js +0 -30
  68. package/dist/jmap/types.js +0 -6
  69. package/dist/logger.js +0 -48
  70. package/dist/mcp/handler.js +0 -255
  71. package/dist/mcp/http.js +0 -29
  72. package/dist/mcp/instructions.js +0 -44
  73. package/dist/mcp/links.js +0 -64
  74. package/dist/mcp/tool-logging.js +0 -67
  75. package/dist/observability/errors.js +0 -41
  76. package/dist/rules/apply.js +0 -236
  77. package/dist/rules/rule.js +0 -280
  78. package/dist/rules/store.js +0 -92
  79. package/dist/tools/annotations.js +0 -71
  80. package/dist/tools/archive-emails.js +0 -40
  81. package/dist/tools/calendar-lookup.js +0 -64
  82. package/dist/tools/contact-common.js +0 -146
  83. package/dist/tools/contact-format.js +0 -72
  84. package/dist/tools/contact-write-through.js +0 -37
  85. package/dist/tools/create-calendar-event.js +0 -231
  86. package/dist/tools/create-calendar.js +0 -54
  87. package/dist/tools/create-contact.js +0 -172
  88. package/dist/tools/create-draft.js +0 -369
  89. package/dist/tools/create-mail-rule.js +0 -101
  90. package/dist/tools/delete-calendar-event.js +0 -165
  91. package/dist/tools/delete-contact.js +0 -60
  92. package/dist/tools/delete-draft.js +0 -129
  93. package/dist/tools/delete-mail-rule.js +0 -38
  94. package/dist/tools/download-attachment.js +0 -90
  95. package/dist/tools/download-email.js +0 -112
  96. package/dist/tools/draft-common.js +0 -600
  97. package/dist/tools/email-types.js +0 -58
  98. package/dist/tools/error-detail.js +0 -10
  99. package/dist/tools/file-emails-common.js +0 -75
  100. package/dist/tools/format.js +0 -131
  101. package/dist/tools/forward-message.js +0 -237
  102. package/dist/tools/forward-quote.js +0 -179
  103. package/dist/tools/get-draft.js +0 -61
  104. package/dist/tools/get-email.js +0 -164
  105. package/dist/tools/get-thread.js +0 -67
  106. package/dist/tools/keywords.js +0 -43
  107. package/dist/tools/list-calendar-events.js +0 -180
  108. package/dist/tools/list-calendars.js +0 -44
  109. package/dist/tools/list-drafts.js +0 -134
  110. package/dist/tools/list-mail-rules.js +0 -28
  111. package/dist/tools/list-unsubscribe.js +0 -152
  112. package/dist/tools/list-upcoming-birthdays.js +0 -165
  113. package/dist/tools/mail-rule-common.js +0 -43
  114. package/dist/tools/mail-rule-format.js +0 -79
  115. package/dist/tools/mailbox-lookup.js +0 -13
  116. package/dist/tools/mark-emails.js +0 -78
  117. package/dist/tools/merge-contacts.js +0 -145
  118. package/dist/tools/move-calendar-events.js +0 -340
  119. package/dist/tools/move-emails.js +0 -64
  120. package/dist/tools/one-click-post.js +0 -275
  121. package/dist/tools/preview-email.js +0 -204
  122. package/dist/tools/preview-mail-rule.js +0 -79
  123. package/dist/tools/reply-quote.js +0 -426
  124. package/dist/tools/reply-to-message.js +0 -292
  125. package/dist/tools/respond-to-event.js +0 -110
  126. package/dist/tools/result.js +0 -9
  127. package/dist/tools/search-contacts.js +0 -431
  128. package/dist/tools/search-emails.js +0 -570
  129. package/dist/tools/send-draft.js +0 -308
  130. package/dist/tools/trash-emails.js +0 -36
  131. package/dist/tools/unsubscribe-from-list.js +0 -249
  132. package/dist/tools/update-calendar-event.js +0 -973
  133. package/dist/tools/update-calendar.js +0 -100
  134. package/dist/tools/update-contact.js +0 -382
  135. package/dist/tools/update-draft.js +0 -714
  136. package/dist/tools/update-mail-rule.js +0 -103
  137. package/dist/tools/upload-attachments.js +0 -126
package/dist/config.js DELETED
@@ -1,219 +0,0 @@
1
- // Reads and validates the server's configuration from the environment and the
2
- // command line. Everything is checked up front, and a misconfigured server
3
- // refuses to start with a message that says what to set.
4
- //
5
- // Nothing here has a default that points anywhere: the Stalwart URL and the
6
- // credential are always the user's own.
7
- import { z } from "zod";
8
- import { isLoopbackHost, urlHostname } from "./http/hosts.js";
9
- const TRAILING_SLASHES_RE = /\/+$/u;
10
- const DEFAULT_HTTP_HOST = "127.0.0.1";
11
- const DEFAULT_HTTP_PORT = 8080;
12
- const MAX_PORT = 65_535;
13
- // Short enough to type by hand is short enough to guess.
14
- const MIN_AUTH_TOKEN_LENGTH = 16;
15
- // What an `Authorization: Bearer` header can carry as one token: visible
16
- // ASCII, no spaces.
17
- const AUTH_TOKEN_RE = /^[\x21-\x7e]+$/u;
18
- const LOOPBACK_HOSTS = new Set([
19
- "localhost",
20
- "127.0.0.1",
21
- "[::1]",
22
- ]);
23
- /** A misconfiguration. `message` is ready to print: it names what to set and never quotes a secret. */
24
- export class ConfigError extends Error {
25
- problems;
26
- constructor(problems) {
27
- super([
28
- "langmail-mcp: cannot start, the configuration is not usable:",
29
- ...problems.map((problem) => ` - ${problem}`),
30
- "See .env.example in the langmail-mcp repository for every setting.",
31
- ].join("\n"));
32
- this.name = "ConfigError";
33
- this.problems = problems;
34
- }
35
- }
36
- // An unset variable and one set to nothing (`STALWART_TOKEN=` in a .env file)
37
- // mean the same.
38
- const unsetWhenEmpty = (value) => value === "" ? undefined : value;
39
- const trimmed = (value) => typeof value === "string" ? unsetWhenEmpty(value.trim()) : value;
40
- // Secrets are taken as they are: a password may begin or end with a space.
41
- const secret = z.preprocess(unsetWhenEmpty, z.string().optional());
42
- const text = z.preprocess(trimmed, z.string().optional());
43
- const parseHttpUrl = (raw) => {
44
- try {
45
- const url = new URL(raw);
46
- return url.protocol === "http:" || url.protocol === "https:"
47
- ? url
48
- : undefined;
49
- }
50
- catch {
51
- // Not a URL at all: the caller reports it.
52
- }
53
- };
54
- const flag = (name) => z.preprocess((value) => (typeof value === "string" ? value.trim().toLowerCase() : value), z
55
- .enum(["", "0", "1", "false", "true"], {
56
- error: `${name} must be 1 (on) or 0 (off).`,
57
- })
58
- .optional()
59
- .transform((value) => value === "1" || value === "true"));
60
- const envSchema = z.object({
61
- LANGMAIL_MCP_ALLOW_REMOTE_IMAGES: flag("LANGMAIL_MCP_ALLOW_REMOTE_IMAGES"),
62
- LANGMAIL_MCP_ALLOW_UNSUBSCRIBE_POST: flag("LANGMAIL_MCP_ALLOW_UNSUBSCRIBE_POST"),
63
- MCP_AUTH_TOKEN: secret,
64
- MCP_HOST: text,
65
- MCP_PORT: z.preprocess(trimmed, z.coerce
66
- .number({ error: "MCP_PORT must be a port number between 1 and 65535." })
67
- .int("MCP_PORT must be a port number between 1 and 65535.")
68
- .min(1, "MCP_PORT must be a port number between 1 and 65535.")
69
- .max(MAX_PORT, "MCP_PORT must be a port number between 1 and 65535.")
70
- .optional()),
71
- MCP_PUBLIC_URL: text,
72
- MCP_TRANSPORT: z.preprocess((value) => (typeof value === "string" ? value.trim().toLowerCase() : value), z
73
- .enum(["", "stdio", "http"], {
74
- error: 'MCP_TRANSPORT must be "stdio" or "http".',
75
- })
76
- .optional()),
77
- STALWART_PASSWORD: secret,
78
- STALWART_TOKEN: secret,
79
- STALWART_URL: text,
80
- STALWART_USERNAME: text,
81
- });
82
- const readStalwartUrl = (env, problems, warnings) => {
83
- if (env.STALWART_URL === undefined) {
84
- problems.push("STALWART_URL is not set. Set it to the base URL of your Stalwart server, for example https://mail.example.com.");
85
- return "";
86
- }
87
- const url = parseHttpUrl(env.STALWART_URL);
88
- if (!url) {
89
- problems.push("STALWART_URL must be an http:// or https:// URL, for example https://mail.example.com.");
90
- return "";
91
- }
92
- if (url.username !== "" || url.password !== "") {
93
- problems.push("STALWART_URL must not contain a username or password. Put them in STALWART_USERNAME and STALWART_PASSWORD.");
94
- return "";
95
- }
96
- if (url.protocol === "http:" && !LOOPBACK_HOSTS.has(url.hostname)) {
97
- warnings.push(`STALWART_URL uses http://, so your credential travels to ${url.host} unencrypted. Use https:// unless that host is on a network you trust.`);
98
- }
99
- return env.STALWART_URL.replace(TRAILING_SLASHES_RE, "");
100
- };
101
- const basicCredential = (username, password) => `Basic ${Buffer.from(`${username}:${password}`, "utf8").toString("base64")}`;
102
- const readCredential = (env, problems) => {
103
- const { STALWART_PASSWORD: password, STALWART_TOKEN: token, STALWART_USERNAME: username, } = env;
104
- const hasBasic = username !== undefined || password !== undefined;
105
- if (token !== undefined && hasBasic) {
106
- problems.push("Both STALWART_TOKEN and STALWART_USERNAME/STALWART_PASSWORD are set. Use one way to sign in: an app password (username and password) or a token.");
107
- return "";
108
- }
109
- if (token !== undefined) {
110
- return `Bearer ${token}`;
111
- }
112
- if (username !== undefined && password !== undefined) {
113
- if (username.includes(":")) {
114
- problems.push("STALWART_USERNAME must not contain a colon (HTTP Basic sign-in cannot carry one).");
115
- return "";
116
- }
117
- return basicCredential(username, password);
118
- }
119
- if (username !== undefined) {
120
- problems.push("STALWART_USERNAME is set but STALWART_PASSWORD is not. Set STALWART_PASSWORD to an app password for that account.");
121
- }
122
- else if (password === undefined) {
123
- problems.push("No credential is set. Set STALWART_USERNAME and STALWART_PASSWORD (an app password), or STALWART_TOKEN.");
124
- }
125
- else {
126
- problems.push("STALWART_PASSWORD is set but STALWART_USERNAME is not. Set STALWART_USERNAME to the account's address.");
127
- }
128
- return "";
129
- };
130
- const readAuthToken = (env, problems) => {
131
- const token = env.MCP_AUTH_TOKEN;
132
- if (token === undefined) {
133
- problems.push("MCP_AUTH_TOKEN is not set. The HTTP transport refuses to start without it: set it to a long random secret, which callers send as `Authorization: Bearer <secret>`.");
134
- return "";
135
- }
136
- if (!AUTH_TOKEN_RE.test(token)) {
137
- problems.push("MCP_AUTH_TOKEN must consist of printable ASCII characters without spaces, because callers send it in an HTTP header. `openssl rand -hex 32` makes one.");
138
- return "";
139
- }
140
- if (token.length < MIN_AUTH_TOKEN_LENGTH) {
141
- problems.push(`MCP_AUTH_TOKEN is too short: it must be at least ${MIN_AUTH_TOKEN_LENGTH} characters. \`openssl rand -hex 32\` makes one.`);
142
- return "";
143
- }
144
- return token;
145
- };
146
- const readHttpTransport = (env, problems, warnings) => {
147
- const host = env.MCP_HOST ?? DEFAULT_HTTP_HOST;
148
- const port = env.MCP_PORT ?? DEFAULT_HTTP_PORT;
149
- let publicUrl = `http://${urlHostname(host)}:${port}`;
150
- if (env.MCP_PUBLIC_URL !== undefined) {
151
- if (parseHttpUrl(env.MCP_PUBLIC_URL)) {
152
- publicUrl = env.MCP_PUBLIC_URL.replace(TRAILING_SLASHES_RE, "");
153
- }
154
- else {
155
- problems.push("MCP_PUBLIC_URL must be an http:// or https:// URL, for example https://mcp.example.com.");
156
- }
157
- }
158
- if (!isLoopbackHost(host)) {
159
- warnings.push(`MCP_HOST is ${host}, so the server is reachable from other machines over plain HTTP, and the bearer token and your mail travel unencrypted. Put a reverse proxy that terminates TLS in front of it, and set MCP_PUBLIC_URL to the https:// address callers use.`);
160
- }
161
- return {
162
- authToken: readAuthToken(env, problems),
163
- host,
164
- kind: "http",
165
- port,
166
- publicUrl,
167
- };
168
- };
169
- const readTransportKind = (env, argv, problems) => {
170
- let fromFlag;
171
- for (const arg of argv) {
172
- if (arg === "--http") {
173
- fromFlag = "http";
174
- }
175
- else if (arg === "--stdio") {
176
- fromFlag = "stdio";
177
- }
178
- else {
179
- problems.push(`Unknown argument ${JSON.stringify(arg)}. The only arguments are --http and --stdio.`);
180
- }
181
- }
182
- return fromFlag ?? (env.MCP_TRANSPORT === "http" ? "http" : "stdio");
183
- };
184
- /**
185
- * Builds the configuration from an environment and the process arguments
186
- * (without the node binary and script). Throws a {@link ConfigError} listing
187
- * every problem at once.
188
- */
189
- export const loadConfig = (rawEnv, argv = []) => {
190
- const parsed = envSchema.safeParse(rawEnv);
191
- if (!parsed.success) {
192
- // The messages name the variable and never echo its value.
193
- throw new ConfigError(parsed.error.issues.map((issue) => issue.message));
194
- }
195
- const env = parsed.data;
196
- const problems = [];
197
- const warnings = [];
198
- const stalwartUrl = readStalwartUrl(env, problems, warnings);
199
- const credential = readCredential(env, problems);
200
- const transport = readTransportKind(env, argv, problems) === "http"
201
- ? readHttpTransport(env, problems, warnings)
202
- : {
203
- kind: "stdio",
204
- ...(env.MCP_PORT === undefined ? {} : { linkPort: env.MCP_PORT }),
205
- };
206
- if (problems.length > 0) {
207
- throw new ConfigError(problems);
208
- }
209
- return {
210
- config: {
211
- allowRemoteImages: env.LANGMAIL_MCP_ALLOW_REMOTE_IMAGES,
212
- allowUnsubscribePost: env.LANGMAIL_MCP_ALLOW_UNSUBSCRIBE_POST,
213
- credential,
214
- stalwartUrl,
215
- transport,
216
- },
217
- warnings,
218
- };
219
- };
@@ -1,79 +0,0 @@
1
- // Address classification: relay/machine detection (never become cards) and
2
- // the work/private context split (freemail domains are private, everything
3
- // else is presumed an organization domain).
4
- // Machine local parts: bounce plumbing, digest senders, and the no-reply
5
- // family. Anchored on separator boundaries so a human like
6
- // `annareply@…` is not swallowed.
7
- const RELAY_LOCAL_RE = /(^|[+._-])(no-?reply|do-?not-?reply|donotreply|mailer-daemon|postmaster|bounces?|notifications?|messaging-digest|newsletters?|digest)([+._-]|$)/iu;
8
- // Domains that only ever relay platform traffic — mail from them pairs the
9
- // platform's name with the platform's address, never a person's.
10
- const RELAY_DOMAINS = new Set([
11
- "amazonses.com",
12
- "facebookmail.com",
13
- "glassdoor.com",
14
- "indeedemail.com",
15
- "instagram.com",
16
- "linkedin.com",
17
- "mailchimpapp.net",
18
- "mandrillapp.com",
19
- "medium.com",
20
- "pinterest.com",
21
- "redditmail.com",
22
- "sendgrid.net",
23
- "substack.com",
24
- "tiktok.com",
25
- "twitter.com",
26
- "x.com",
27
- ]);
28
- // Freemail (and our own) domains: an address here is a person's private
29
- // address; anything else is presumed a work/organization domain. People who
30
- // use one address for everything make the split a no-op, which is fine.
31
- const PRIVATE_DOMAINS = new Set([
32
- "aol.com",
33
- "fastmail.com",
34
- "freenet.de",
35
- "gmail.com",
36
- "gmx.at",
37
- "gmx.ch",
38
- "gmx.de",
39
- "gmx.net",
40
- "googlemail.com",
41
- "hotmail.com",
42
- "hotmail.de",
43
- "icloud.com",
44
- "langmail.me",
45
- "live.com",
46
- "mac.com",
47
- "mail.com",
48
- "me.com",
49
- "outlook.com",
50
- "outlook.de",
51
- "posteo.de",
52
- "proton.me",
53
- "protonmail.com",
54
- "t-online.de",
55
- "web.de",
56
- "yahoo.com",
57
- "yahoo.de",
58
- ]);
59
- export const normalizeAddress = (address) => address.trim().toLowerCase();
60
- const domainOf = (address) => normalizeAddress(address).split("@")[1] ?? "";
61
- const localOf = (address) => normalizeAddress(address).split("@")[0] ?? "";
62
- // The domain itself or any parent domain (bounce.linkedin.com → linkedin.com).
63
- const inDomainSet = (domain, set) => {
64
- let d = domain;
65
- while (d) {
66
- if (set.has(d)) {
67
- return true;
68
- }
69
- const dot = d.indexOf(".");
70
- if (dot === -1) {
71
- return false;
72
- }
73
- d = d.slice(dot + 1);
74
- }
75
- return false;
76
- };
77
- export const isRelayAddress = (address) => RELAY_LOCAL_RE.test(localOf(address)) ||
78
- inDomainSet(domainOf(address), RELAY_DOMAINS);
79
- export const classifyContext = (address) => inDomainSet(domainOf(address), PRIVATE_DOMAINS) ? "private" : "work";
@@ -1,81 +0,0 @@
1
- // Pure calendar arithmetic for "whose birthday is coming up": the next
2
- // occurrence of a month/day on or after a given date, and the distance in
3
- // days. Kept apart from the MCP tool so the year-boundary and leap-day rules
4
- // are unit-tested without an address book.
5
- //
6
- // No `Date` objects cross this boundary. Everything is a `{ year, month,
7
- // day }` triple, and the one place a `Date` is used internally is UTC-only,
8
- // so a birthday can never shift by a day with the server's time zone.
9
- const DAY_MS = 86_400_000;
10
- const isLeapYear = (year) => (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
11
- // Days in a month, February by the year given.
12
- export const daysInMonth = (year, month) => {
13
- if (month === 2) {
14
- return isLeapYear(year) ? 29 : 28;
15
- }
16
- return [4, 6, 9, 11].includes(month) ? 30 : 31;
17
- };
18
- const epochDay = (d) => Date.UTC(d.year, d.month - 1, d.day) / DAY_MS;
19
- // The stored month/day placed in a given year. Feb 29 falls on Feb 28 in a
20
- // year that has no Feb 29 — the one convention the tool description states.
21
- const inYear = (birthday, year) => ({
22
- day: Math.min(birthday.day, daysInMonth(year, birthday.month)),
23
- month: birthday.month,
24
- year,
25
- });
26
- const isBefore = (a, b) => epochDay(a) < epochDay(b);
27
- // The next calendar date on or after `from` on which the birthday falls. A
28
- // birthday on `from` itself is `from`. When the birth year is known the
29
- // answer is never earlier than the birth date: a window that starts a year
30
- // ahead of it still contains the day the person was born (turning 0),
31
- // and nobody turns -10.
32
- export const nextOccurrence = (birthday, from) => {
33
- const thisYear = inYear(birthday, from.year);
34
- const next = isBefore(thisYear, from)
35
- ? inYear(birthday, from.year + 1)
36
- : thisYear;
37
- return birthday.year !== undefined && next.year < birthday.year
38
- ? inYear(birthday, birthday.year)
39
- : next;
40
- };
41
- // Whole days from `from` to `occurrence`; the same day is 0.
42
- export const daysUntil = (occurrence, from) => Math.round(epochDay(occurrence) - epochDay(from));
43
- // `YYYY-MM-DD`, zero-padded.
44
- export const formatCalendarDate = (d) => `${String(d.year).padStart(4, "0")}-${String(d.month).padStart(2, "0")}-${String(d.day).padStart(2, "0")}`;
45
- const ISO_DATE = /^(\d{4})-(\d{2})-(\d{2})$/u;
46
- // Strict `YYYY-MM-DD` to a calendar date, rejecting impossible dates.
47
- export const parseCalendarDate = (text) => {
48
- const m = ISO_DATE.exec(text.trim());
49
- if (!m) {
50
- return;
51
- }
52
- const year = Number(m[1]);
53
- const month = Number(m[2]);
54
- const day = Number(m[3]);
55
- if (month < 1 || month > 12 || day < 1 || day > daysInMonth(year, month)) {
56
- return;
57
- }
58
- return { day, month, year };
59
- };
60
- // The calendar day `now` falls on in an IANA time zone — the tool's default
61
- // `from`. The user's day, not the server's: at 17:30 in Los Angeles it is
62
- // already tomorrow in UTC, and "whose birthday is today" must not skip
63
- // today. An unknown zone falls back to UTC rather than failing the call.
64
- export const todayIn = (now, timeZone) => {
65
- const parts = (zone) =>
66
- // en-CA formats as `YYYY-MM-DD`, which parseCalendarDate reads.
67
- parseCalendarDate(new Intl.DateTimeFormat("en-CA", {
68
- day: "2-digit",
69
- month: "2-digit",
70
- timeZone: zone,
71
- year: "numeric",
72
- }).format(now));
73
- let day;
74
- try {
75
- day = parts(timeZone);
76
- }
77
- catch {
78
- day = undefined;
79
- }
80
- return day ?? parts("UTC");
81
- };
@@ -1,58 +0,0 @@
1
- // Mapping between the collection domain and the JSContact card shape —
2
- // reading the extension property defensively (cards are user-editable in
3
- // any CardDAV client) and small helpers the fold shares with the reader.
4
- import { normalizeAddress } from "./address-class.js";
5
- import { COLLECTED_NOTE_KEY, COLLECTED_NOTE_TEXT, COLLECTED_PROPERTY, } from "./constants.js";
6
- const SOURCES = new Set(["authored", "derived", "imported"]);
7
- const emptyExtension = () => ({
8
- addresses: {},
9
- interactions: [],
10
- });
11
- // The machine-owned note entry carrying the collection payload — Stalwart
12
- // round-trips vendor properties inside entry objects but not at the Card's
13
- // top level (see constants.ts).
14
- export const collectedNoteEntry = (ext) => ({
15
- [COLLECTED_PROPERTY]: ext,
16
- note: COLLECTED_NOTE_TEXT,
17
- });
18
- // Defensive read: a CardDAV client may have mangled or dropped parts of the
19
- // machine-owned entry; missing pieces degrade to empty, never throw.
20
- export const readCollected = (card) => {
21
- const raw = card.notes?.[COLLECTED_NOTE_KEY]?.[COLLECTED_PROPERTY];
22
- if (!raw || typeof raw !== "object") {
23
- return emptyExtension();
24
- }
25
- const ext = raw;
26
- return {
27
- ...(Array.isArray(ext.absorbed) && ext.absorbed.length > 0
28
- ? { absorbed: ext.absorbed }
29
- : {}),
30
- addresses: typeof ext.addresses === "object" && ext.addresses ? ext.addresses : {},
31
- interactions: Array.isArray(ext.interactions) ? ext.interactions : [],
32
- ...(Array.isArray(ext.relays) && ext.relays.length > 0
33
- ? { relays: ext.relays }
34
- : {}),
35
- // Round-tripped rather than re-derived: every fold rebuilds the entry
36
- // from what it read here, so the marker survives later collection.
37
- ...(ext.source && SOURCES.has(ext.source) ? { source: ext.source } : {}),
38
- };
39
- };
40
- export const cardAddresses = (card) => Object.values(card.emails ?? {}).map((e) => normalizeAddress(e.address));
41
- // Exact normalized display-name match is the merge gate: lowercased,
42
- // whitespace collapsed. Nothing fuzzier — a wrong merge silently corrupts a
43
- // user-visible address book, a missed merge merely shows two candidates.
44
- export const normalizeName = (name) => name.trim().replace(/\s+/gu, " ").toLowerCase();
45
- // First free `<prefix><n>` key: existing cards keep their key scheme, we only
46
- // ever add — so a handle printed in one response stays valid in the next.
47
- export const nextKey = (existing, prefix) => {
48
- let n = 0;
49
- while (`${prefix}${n}` in (existing ?? {})) {
50
- n += 1;
51
- }
52
- return `${prefix}${n}`;
53
- };
54
- export const nextEmailKey = (emails) => nextKey(emails, "e");
55
- // Deterministic uid so a crashed-and-retried create of the same person
56
- // resolves to the same identity instead of minting a new one.
57
- export const COLLECTED_UID_PREFIX = "urn:langmail:collected:";
58
- export const collectedUid = (address) => `${COLLECTED_UID_PREFIX}${normalizeAddress(address)}`;
@@ -1,46 +0,0 @@
1
- // Every tunable threshold of the collection pipeline in one place, so
2
- // re-grading the address book is a constant change, never a re-collection
3
- // (relationship tiers are computed at read time from stored counters).
4
- // Name of the machine-maintained address book, provisioned lazily on first
5
- // write. Visible in CardDAV clients — benign, since cards carry no mail
6
- // content (see the extension-property comment in types.ts).
7
- export const COLLECTED_BOOK_NAME = "Collected";
8
- // Vendor extension property (RFC 9553 §1.3: prefixed with a domain the
9
- // vendor controls) carrying the collection data. Stalwart rejects vendor
10
- // properties at the Card's top level but round-trips them inside entry
11
- // objects, so the payload lives inside a dedicated, machine-owned note
12
- // entry: `notes[COLLECTED_NOTE_KEY][COLLECTED_PROPERTY]`. Collection
13
- // updates that entry freely (via the scoped COLLECTED_PATCH_PATH, never
14
- // touching user-authored notes), while standard properties only ever have
15
- // blanks filled.
16
- export const COLLECTED_PROPERTY = "langmail.me:collected";
17
- export const COLLECTED_NOTE_KEY = "langmail-collected";
18
- // Book create_contact provisions when the account has no address book at
19
- // all — deliberately not the collected one, which is machine-maintained.
20
- export const PERSONAL_BOOK_NAME = "Contacts";
21
- // Note entry the contact tools write a user-authored note into, when the
22
- // card doesn't already carry exactly one note of its own (see profile.ts).
23
- export const USER_NOTE_KEY = "langmail-note";
24
- // Anniversary entry the contact tools write a birthday into, when the card
25
- // doesn't already carry a `birth` entry under some other key (see
26
- // profile.ts). A foreign client's key is reused so the edit lands in place.
27
- export const BIRTHDAY_KEY = "langmail-birthday";
28
- // The visible note text CardDAV clients render for the entry — a short
29
- // explanation instead of raw data (the payload itself is invisible to
30
- // standard clients).
31
- export const COLLECTED_NOTE_TEXT = "Maintained by Langmail contact collection.";
32
- // RFC 8620 §5.3 PatchObject path updating only our note entry.
33
- export const COLLECTED_PATCH_PATH = `notes/${COLLECTED_NOTE_KEY}`;
34
- // `active` needs at least this many interactions …
35
- export const ACTIVE_MIN_INTERACTIONS = 3;
36
- // … one of which within this many days.
37
- export const ACTIVE_RECENT_DAYS = 60;
38
- // Above this many attendees, an event stops being evidence of a personal
39
- // relationship: attendee sightings grade `weak` (the workshop case).
40
- export const LARGE_EVENT_ATTENDEES = 8;
41
- // The interaction log keeps the last N sightings as content-free tuples …
42
- export const INTERACTION_LOG_SIZE = 5;
43
- // … of which concise output shows the most recent M.
44
- export const SHOWN_INTERACTIONS = 3;
45
- // Relay addresses remembered per person (for the excluded_relays output).
46
- export const RELAY_LIST_SIZE = 5;