Skip to main content

Email Piping Subjects still rubbish

It's been a while since I moaned about this, so I thought I'd get another in.

Ticket, subject "Website Updates" - closed for over a month.

New email comes in, subject "updates" - reopens old ticket (with a different subject!) and makes it look like the ticket has been waiting for a month.

1.00

As soon as a ticket is opened, the emails that go back and forth include the ticket number in the subject line.

  • Email comes in without a ticket number - new ticket.
  • Email comes in with a ticket number - update existing ticket.

Jonathan Gwyer

Gosh, is it really a month since my last whinge?

Today's example - old ticket titled "Website updates and prices" re-opened and updated by an email with the subject "Website update"

Is there any hope that email piping might get some improvements soon, Shahjahan JewelΒ ?

Would it be so difficult to base it on the ticket number?

Roelinde Brons

I wrote a snippet for it. It is working on the most basic situation

Jonathan Gwyer

Roelinde BronsΒ sounds interesting, could you share?

Roelinde Brons

Jonathan GwyerΒ hi Jonathan, sorry for my late reply. The snippet is not solid working enough right now (I noticed last week).

Because I mis some more β€˜basic’ email behavior, I ended up creating a whole new plugin this week using webhook URL woth Postmark.

I will share more about that the coming week here in the community. My team will do a solid test first.

Roelinde Brons

Jonathan GwyerΒ below you can the snippet for inspiration, but we turned it off for now.

For the plugin I did a more deepdive, with a more robust solution

/**

  • FluentSupport workaround:
    • Nieuwe losse mails met hetzelfde onderwerp worden aparte tickets.
    • Replies blijven gekoppeld via ticketnummer in subject.
      */

/**

  1. Zet ticketnummer in uitgaande mails naar klant.
    */
    add_filter('fluent_support/ticket_email_subject', function ($subject, $ticket, $emailType) {

$customerEmailTypes = [
'ticket_created_email_to_customer',
'ticket_replied_by_agent_email_to_customer',
'ticket_closed_by_agent_email_to_customer',
];

if (!in_array($emailType, $customerEmailTypes, true)) {
return $subject;
}

if (empty($ticket->id)) {
return $subject;
}

if (preg_match('/#' . preg_quote((string) $ticket->id, '/') . '\b/', $subject)) {
return $subject;
}

return $subject . ' #' . $ticket->id;

}, 10, 3);

/**

    1. Nieuwe inkomende mails tijdelijk uniek maken,
  • zodat FluentSupport ze niet samenvoegt op alleen onderwerp.
    */
    add_filter('fluent_support_pro/email_piping_data', function ($formattedData, $rawData, $box) {

    $subject = $formattedData['subject'] ?? '';

    // Laat mails met ticketnummer met rust.
    if (preg_match('/#\d+\b/', $subject)) {
    return $formattedData;
    }

    // Laat duidelijke replies/forwards met rust.
    if (preg_match('/^\s*(re|aw|fw|fwd):/i', $subject)) {
    return $formattedData;
    }

    $messageId = $formattedData['message_id'] ?? ($rawData['messageId'] ?? '');

    if (!$messageId) {
    return $formattedData;
    }

    $hash = substr(md5($messageId), 0, 10);

    $formattedData['subject'] = $subject . ' [fs-new-' . $hash . ']';

    return $formattedData;

}, 10, 3);

/**

    1. Tijdelijke suffix weer verwijderen uit nieuw aangemaakte tickets.
      */
      add_action('fluent_support/after_ticket_create_from_email', function ($ticket, $customer) {

    if (empty($ticket->title)) {
    return;
    }

    $cleanTitle = preg_replace('/\s?[fs-new-[a-f0-9]{10}]$/', '', $ticket->title);

    if ($cleanTitle && $cleanTitle !== $ticket->title) {
    $ticket->title = $cleanTitle;
    $ticket->save();
    }

}, 10, 2);