Skip to content

Commit 26caa7f

Browse files
committed
ack PR comments
1 parent d5bcc14 commit 26caa7f

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

apps/sim/blocks/blocks/imap.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export const ImapBlock: BlockConfig = {
2121
},
2222
},
2323
inputs: {
24-
// Connection settings (stored in providerConfig)
2524
host: { type: 'string', description: 'IMAP server hostname' },
2625
port: { type: 'string', description: 'IMAP server port' },
2726
secure: { type: 'boolean', description: 'Use SSL/TLS encryption' },
@@ -34,7 +33,6 @@ export const ImapBlock: BlockConfig = {
3433
includeAttachments: { type: 'boolean', description: 'Include email attachments' },
3534
},
3635
outputs: {
37-
// Trigger outputs (from email)
3836
messageId: { type: 'string', description: 'RFC Message-ID header' },
3937
subject: { type: 'string', description: 'Email subject line' },
4038
from: { type: 'string', description: 'Sender email address' },

apps/sim/blocks/registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ export const registry: Record<string, BlockConfig> = {
196196
huggingface: HuggingFaceBlock,
197197
human_in_the_loop: HumanInTheLoopBlock,
198198
hunter: HunterBlock,
199-
imap: ImapBlock,
200199
image_generator: ImageGeneratorBlock,
200+
imap: ImapBlock,
201201
incidentio: IncidentioBlock,
202202
input_trigger: InputTriggerBlock,
203203
intercom: IntercomBlock,

apps/sim/lib/webhooks/imap-polling-service.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { db } from '@sim/db'
22
import { webhook, workflow } from '@sim/db/schema'
33
import { createLogger } from '@sim/logger'
4+
import type { InferSelectModel } from 'drizzle-orm'
45
import { and, eq, sql } from 'drizzle-orm'
56
import type { FetchMessageObject, MailboxLockObject } from 'imapflow'
67
import { ImapFlow } from 'imapflow'
@@ -11,6 +12,8 @@ import { MAX_CONSECUTIVE_FAILURES } from '@/triggers/constants'
1112

1213
const logger = createLogger('ImapPollingService')
1314

15+
type WebhookRecord = InferSelectModel<typeof webhook>
16+
1417
interface ImapWebhookConfig {
1518
host: string
1619
port: number
@@ -489,6 +492,27 @@ function extractAttachmentsFromSource(
489492
return attachments
490493
}
491494

495+
/**
496+
* Checks if a body structure contains attachments by examining disposition
497+
*/
498+
function hasAttachmentsInBodyStructure(structure: FetchMessageObject['bodyStructure']): boolean {
499+
if (!structure) return false
500+
501+
if (structure.disposition === 'attachment') {
502+
return true
503+
}
504+
505+
if (structure.disposition === 'inline' && structure.dispositionParameters?.filename) {
506+
return true
507+
}
508+
509+
if (structure.childNodes && Array.isArray(structure.childNodes)) {
510+
return structure.childNodes.some((child) => hasAttachmentsInBodyStructure(child))
511+
}
512+
513+
return false
514+
}
515+
492516
async function processEmails(
493517
emails: Array<{
494518
uid: number
@@ -497,7 +521,7 @@ async function processEmails(
497521
bodyStructure: FetchMessageObject['bodyStructure']
498522
source?: Buffer
499523
}>,
500-
webhookData: any,
524+
webhookData: WebhookRecord,
501525
config: ImapWebhookConfig,
502526
requestId: string
503527
) {
@@ -539,9 +563,7 @@ async function processEmails(
539563
: { text: '', html: '' }
540564

541565
let attachments: ImapAttachment[] = []
542-
const hasAttachments = email.bodyStructure
543-
? JSON.stringify(email.bodyStructure).toLowerCase().includes('attachment')
544-
: false
566+
const hasAttachments = hasAttachmentsInBodyStructure(email.bodyStructure)
545567

546568
if (config.includeAttachments && hasAttachments && email.source) {
547569
attachments = extractAttachmentsFromSource(email.source, email.bodyStructure)
@@ -573,7 +595,7 @@ async function processEmails(
573595
method: 'POST',
574596
headers: {
575597
'Content-Type': 'application/json',
576-
'X-Webhook-Secret': webhookData.secret || '',
598+
'X-Webhook-Secret': '',
577599
'User-Agent': 'Sim/1.0',
578600
},
579601
body: JSON.stringify(payload),

apps/sim/lib/workflows/comparison/compare.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { WorkflowState } from '@/stores/workflows/workflow/types'
2-
import { TRIGGER_RUNTIME_SUBBLOCK_IDS } from '@/triggers/constants'
2+
import { SYSTEM_SUBBLOCK_IDS, TRIGGER_RUNTIME_SUBBLOCK_IDS } from '@/triggers/constants'
33
import {
44
normalizedStringify,
55
normalizeEdge,
@@ -103,11 +103,13 @@ export function hasWorkflowChanged(
103103
subBlocks: undefined,
104104
}
105105

106-
// Get all subBlock IDs from both states, excluding runtime metadata
106+
// Get all subBlock IDs from both states, excluding runtime metadata and UI-only elements
107107
const allSubBlockIds = [
108108
...new Set([...Object.keys(currentSubBlocks), ...Object.keys(deployedSubBlocks)]),
109109
]
110-
.filter((id) => !TRIGGER_RUNTIME_SUBBLOCK_IDS.includes(id))
110+
.filter(
111+
(id) => !TRIGGER_RUNTIME_SUBBLOCK_IDS.includes(id) && !SYSTEM_SUBBLOCK_IDS.includes(id)
112+
)
111113
.sort()
112114

113115
// Normalize and compare each subBlock

0 commit comments

Comments
 (0)