-
Notifications
You must be signed in to change notification settings - Fork 3
feat(imap) module #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
uuganaa1007
wants to merge
8
commits into
main
Choose a base branch
from
inbox-imap
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(imap) module #143
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c43f8f1
feat(imap) module
uuganaa1007 a01331b
refactor
uuganaa1007 631d89a
refactor
uuganaa1007 4f43fdb
refactor
uuganaa1007 620be6f
refactor
uuganaa1007 c0ab5ca
refactor sourcery-ai
uuganaa1007 0005f8e
coderabbitai
uuganaa1007 e4c77cf
coderabbitai refactor
uuganaa1007 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
11 changes: 11 additions & 0 deletions
11
backend/plugins/frontline_api/src/modules/integrations/imap/@types/customers.ts
This file contains hidden or 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,11 @@ | ||
| import { Document } from 'mongoose'; | ||
| export interface IIMapCustomer { | ||
| inboxIntegrationId: string; | ||
| contactsId: string; | ||
| email: string; | ||
| firstName?: string; | ||
| lastName?: string; | ||
| integrationId?: string; | ||
| } | ||
|
|
||
| export interface IIMapCustomerDocument extends IIMapCustomer, Document {} |
15 changes: 15 additions & 0 deletions
15
backend/plugins/frontline_api/src/modules/integrations/imap/@types/integrations.ts
This file contains hidden or 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,15 @@ | ||
| import { Document } from 'mongoose'; | ||
| export interface IIMapIntegration { | ||
| inboxId: string; | ||
| host: string; | ||
| smtpHost: string; | ||
| smtpPort: string; | ||
| mainUser: string; | ||
| user: string; | ||
| password: string; | ||
| healthStatus?: string; | ||
| error?: string; | ||
| lastFetchDate?: Date; | ||
| } | ||
|
|
||
| export interface IIMapIntegrationDocument extends IIMapIntegration, Document {} | ||
47 changes: 47 additions & 0 deletions
47
backend/plugins/frontline_api/src/modules/integrations/imap/@types/messages.ts
This file contains hidden or 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,47 @@ | ||
| import { Document } from 'mongoose'; | ||
|
|
||
| interface IIMapMail { | ||
| name: string; | ||
| address: string; | ||
| } | ||
| export interface IIMapAttachmentParams { | ||
| filename: string; | ||
| size: number; | ||
| mimeType: string; | ||
| data?: string; | ||
| attachmentId?: string; | ||
| } | ||
| export interface IIMapMessage { | ||
| inboxIntegrationId: string; | ||
| inboxConversationId: string; | ||
| messageId: string; | ||
| subject: string; | ||
| body: string; | ||
| to: IIMapMail[]; | ||
| cc: IIMapMail[]; | ||
| bcc: IIMapMail[]; | ||
| from: IIMapMail[]; | ||
| attachments?: IIMapAttachmentParams[]; | ||
| createdAt: Date; | ||
| } | ||
|
|
||
| export interface ImapSendMailInput { | ||
| to: string | string[]; | ||
| subject: string; | ||
| body:string; | ||
| text: string; | ||
| html?: string; | ||
| from?: string; | ||
| conversationId?: string; | ||
| integrationId?: string; | ||
| customerId?: string; | ||
| attachments?: Array<{name: string; url: string; type?: string; size?: number}>; | ||
| replyToMessageId?: string; | ||
| shouldOpen?: boolean; | ||
| shouldResolve?: boolean; | ||
| cc?: string[]; | ||
| bcc?: string[]; | ||
| replyTo?: string; | ||
| } | ||
|
|
||
| export interface IIMapMessageDocument extends IIMapMessage, Document {} |
9 changes: 9 additions & 0 deletions
9
backend/plugins/frontline_api/src/modules/integrations/imap/db/definitions/customers.ts
This file contains hidden or 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,9 @@ | ||
|
|
||
| import { Schema } from 'mongoose'; | ||
| export const customerSchema = new Schema({ | ||
| inboxIntegrationId: { type: String, required: true }, | ||
| contactsId:{ type: String}, | ||
| email: { type: String, unique: true }, | ||
| firstName: { type: String }, | ||
| lastName: { type: String }, | ||
| }); |
20 changes: 20 additions & 0 deletions
20
backend/plugins/frontline_api/src/modules/integrations/imap/db/definitions/integrations.ts
This file contains hidden or 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,20 @@ | ||
| import { Schema } from 'mongoose'; | ||
| export const integrationSchema = new Schema({ | ||
| inboxId: { type: String, required: true }, | ||
| host: { type: String, required: true }, | ||
| smtpHost: { type: String, required: true }, | ||
| smtpPort: { | ||
| type: String, | ||
| required: true, | ||
| validate: { | ||
| validator: (v: string) => /^\d+$/.test(v) && parseInt(v) > 0 && parseInt(v) <= 65535, | ||
| message: 'smtpPort must be a valid port number' | ||
| } | ||
| }, | ||
| mainUser: { type: String, required: true }, | ||
| user: { type: String, required: true }, | ||
| password: { type: String, required: true }, | ||
| healthStatus: String, | ||
| error: String, | ||
| lastFetchDate: Date, | ||
| }); |
45 changes: 45 additions & 0 deletions
45
backend/plugins/frontline_api/src/modules/integrations/imap/db/definitions/messages.ts
This file contains hidden or 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,45 @@ | ||
| import { Schema } from 'mongoose'; | ||
| export const attachmentSchema = new Schema({ | ||
| filename: { type: String, required: true }, | ||
| mimeType: { type: String, required: true }, | ||
| type: { type: String, required: true }, | ||
| size: { | ||
| type: Number, | ||
| required: true, | ||
| min: 1, | ||
| validate: { | ||
| validator: Number.isFinite, | ||
| message: 'Size must be a valid number' | ||
| } | ||
| }, | ||
| attachmentId: { type: String, required: true } | ||
| }, { _id: false }); | ||
|
|
||
| const emailSchema = new Schema( | ||
| { | ||
| name: { type: String }, | ||
| address: { type: String }, | ||
| }, | ||
| { _id: false } | ||
| ); | ||
|
|
||
| export const messageSchema = new Schema({ | ||
| inboxIntegrationId: { type: String, required: true }, | ||
| inboxConversationId: { type: String, required: true }, | ||
| subject: { type: String, required: true }, | ||
| messageId: { type: String, required: true, unique: true }, | ||
| inReplyTo: { type: String }, | ||
| references: [String], | ||
| body: { type: String, required: true }, | ||
| to: { type: [emailSchema], required: true }, | ||
| cc: [emailSchema], | ||
| bcc: [emailSchema], | ||
| from: { type: [emailSchema], required: true }, | ||
| attachments: [attachmentSchema], | ||
| createdAt: { type: Date, index: true, default: Date.now }, | ||
| type: { | ||
| type: String, | ||
| enum: ['SENT', 'INBOX'], | ||
| required: true | ||
| } | ||
| }); |
13 changes: 13 additions & 0 deletions
13
backend/plugins/frontline_api/src/modules/integrations/imap/db/models/Customers.ts
This file contains hidden or 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,13 @@ | ||
| import { Model } from 'mongoose'; | ||
| import {IIMapCustomerDocument} from '@/integrations/imap/@types/customers'; | ||
| import { customerSchema } from '@/integrations/imap/db/definitions/customers' | ||
| export type IIMapCustomerModel = Model<IIMapCustomerDocument>; | ||
|
|
||
|
|
||
| export const loadImapCustomerClass = (models) => { | ||
| class Customer {} | ||
|
|
||
| customerSchema.loadClass(Customer); | ||
|
|
||
| return customerSchema; | ||
| }; |
12 changes: 12 additions & 0 deletions
12
backend/plugins/frontline_api/src/modules/integrations/imap/db/models/Integrations.ts
This file contains hidden or 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,12 @@ | ||
| import { Model } from 'mongoose'; | ||
| import { IIMapIntegrationDocument} from '@/integrations/imap/@types/integrations'; | ||
| import { integrationSchema } from '@/integrations/imap/db/definitions/integrations' | ||
| export type IIMapIntegrationModel = Model<IIMapIntegrationDocument>; | ||
|
|
||
| export const loadImapIntegrationClass = (models) => { | ||
| class Integration {} | ||
|
|
||
| integrationSchema.loadClass(Integration); | ||
|
|
||
| return integrationSchema; | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Store credentials securely
The interface stores sensitive data like password as plain text. This could pose a security risk if database records are exposed.
Consider implementing credential encryption at rest. One approach is to use environment-specific encryption keys to encrypt sensitive fields before storage and decrypt when needed.
🏁 Script executed:
Length of output: 16805
🏁 Script executed:
Length of output: 2149
Encrypt IMAP integration credentials at rest
The IMAP integration’s
password(and similar sensitive fields) are currently defined and stored as plain strings with no encryption layer applied:• backend/plugins/frontline_api/src/modules/integrations/imap/@types/integrations.ts
• backend/plugins/frontline_api/src/modules/integrations/imap/db/definitions/integrations.ts
Our searches (
rg -i encrypt) show no encryption implementation in the repo beyond lockfile entries and a frontendENCRYPTION_KEYconstant. To protect these credentials:– Mongoose plugins (e.g., mongoose-field-encryption)
– MongoDB Client-Side Field Level Encryption (
mongodb-client-encryption)ENCRYPTION_KEY).🤖 Prompt for AI Agents