Skip to content

getRecipients drops incoming email To recipients from the reply CC #67

Description

@limehawk

getRecipients builds the reply recipients from the last email in a conversation. For an incoming email, it is expected to move extra To recipients into the reply cc (minus the inbox address). It does not. The incoming branch hardcodes the To list to empty:

if (isIncoming) {
  ...
  emailAttributes = {
    cc: email?.cc || [],
    bcc: email?.bcc || [],
    from: email?.from || [],
    to: [],   // <-- drops the email's actual To recipients
  };
}

So this later step is always a no-op for incoming emails:

// Only include 'to' recipients in cc for incoming emails, not for outgoing
if (Array.isArray(emailAttributes.to) && isIncoming) {
  cc.push(...emailAttributes.to);
}

Effect in Chatwoot: a customer sends an email to the inbox with a colleague in the To line (not CC). The agent replies from the dashboard. The reply box computes an empty CC and the colleague silently falls off the thread.

Repro:

getRecipients(
  incomingEmail({ from: ['customer@example.com'], to: ['inbox@co.com', 'colleague@example.com'] }),
  'customer@example.com',
  'inbox@co.com',
  ''
);
// actual:   cc = []
// expected: cc = ['colleague@example.com']

Regression: before #43 the function read the raw email object, so emailAttributes.to held the real To list and the cc.push worked. #43 restructured the branches and zeroed to for incoming; #50 kept the guard but the array is always empty. There is no test covering an incoming email with extra To recipients — the createIncomingEmail fixture has no to field at all.

Fix incoming: pass email?.to || [] so the existing cc-building step and filters work again.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions