@bobfrankston/iflow 1.0.2 → 1.0.3

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.
package/imaplib/types.ts DELETED
@@ -1,105 +0,0 @@
1
- import imapflow from 'imapflow';
2
-
3
- // Simple map implementation to replace maplca dependency
4
- class SimpleMap<T> {
5
- private items: Record<string, T[]> = {};
6
-
7
- add(key: string, value: T) {
8
- const k = key.toLowerCase();
9
- if (!this.items[k]) this.items[k] = [];
10
- this.items[k].push(value);
11
- }
12
-
13
- get(key: string): T[] | undefined {
14
- return this.items[key.toLowerCase()];
15
- }
16
- }
17
-
18
- export type MessageEnvelope = imapflow.MessageEnvelopeObject;
19
-
20
- export interface ImapClientConfig {
21
- server: string;
22
- port: number;
23
- username: string;
24
- password: string;
25
- verbose?: boolean;
26
- }
27
-
28
- // export interface ImapClientConfig {
29
- // server: string;
30
- // port: number;
31
- // username: string;
32
- // password?: string; // Make optional for OAuth
33
- // oauth?: {
34
- // accessToken: string;
35
- // refreshToken: string;
36
- // clientId: string;
37
- // clientSecret: string;
38
- // };
39
- // verbose?: boolean;
40
- // }
41
-
42
- export interface FetchQuery extends imapflow.FetchQueryObject {
43
- }
44
-
45
- export type FetchPart = keyof imapflow.FetchQueryObject;
46
-
47
- export class FetchedMessage {
48
- private fmo: imapflow.FetchMessageObject;
49
- parsedHeader: string[][];
50
- headerSet: SimpleMap<string>;
51
- _source: string;
52
-
53
- constructor(init: imapflow.FetchMessageObject) {
54
- this.fmo = init;
55
- this._source = init.source?.toString('utf8');
56
- this.parsedHeader = this.fmo.headers.toString('utf8')
57
- .replace(/\r\n(\s)/g, '$1')
58
- .split('\r\n')
59
- .filter(line => line.trim() !== '')
60
- .map(line => line.split(': ', 2));
61
- this.headerSet = new SimpleMap<string>();
62
- this.parsedHeader.forEach(([k, v]) => this.headerSet.add(k, v));
63
- delete this.fmo.headers;
64
- }
65
-
66
- get flagged() { return this.fmo.flags.has('\\Flagged'); }
67
- get answered() { return this.fmo.flags.has('\\Answered'); }
68
- get deleted() { return this.fmo.flags.has('\\Deleted'); }
69
- get seen() { return this.fmo.flags.has('\\Seen'); }
70
- get unread() { return !this.seen; }
71
- get draft() { return this.fmo.flags.has('\\Draft'); }
72
- get hasFlag() { return this.fmo.flags.size > 0; }
73
-
74
- get to() { return this.envelope.to; }
75
- get cc() { return this.envelope.cc; }
76
- get bcc() { return this.envelope.bcc; }
77
- get from() { return this.envelope.from; }
78
- get replyTo() { return this.envelope.replyTo; }
79
- get sender() { return this.envelope.sender; }
80
- get date() { return this.envelope.date; }
81
- get ymd() { return this.date?.toLocaleDateString('se'); }
82
- get tcsb() { return (this as any as Record<string, string[]>); } // tcsb = to, cc, bcc
83
-
84
- get seq() { return this.fmo.seq; }
85
- get uid() { return this.fmo.uid; }
86
- get modseq() { return this.fmo.modseq; }
87
- private get envelope() { return this.fmo.envelope; }
88
- private get flags() { return this.fmo.flags; }
89
- get internalDate() { return this.fmo.internalDate; }
90
- get size() { return this.fmo.size; }
91
- get bodyStructure() { return this.fmo.bodyStructure; }
92
- get source() { return this._source; }
93
-
94
- get messageId() { return this.envelope.messageId; }
95
- get listUnsubscribe() { return this.headerSet.get('List-Unsubscribe')?.[0]; }
96
- get xpriority() { return this.headerSet.get('X-Priority')?.[0]; }
97
- get importance() { return this.headerSet.get('Importance')?.[0]; }
98
-
99
- get deliveredTo() { return this.headerSet.get('Delivered-To')?.[0]; }
100
- get subject() { return this.envelope.subject; }
101
-
102
- // if you still need raw headers or bodyParts you can add:
103
- // get rawHeaders() { return this.fmo.headers; }
104
- // get bodyParts() { return this.fmo.bodyParts; }
105
- }