Changing cfattachwrn.dat to HTML message | MDaemon Technologies, Ltd.

Changing cfattachwrn.dat to HTML message


  • Is it possible to customize the message from the cfattachwrn.dat file and replace it with an HTML formatted message that users would receive instead of the plain text one?

    Here’s the current default template:

    # This template is used by the content filter
    #
    # Note: lines beginning with # are comments
    #
    
    ******************************* WARNING *******************************
    The message has been scanned by MDaemon's Content Filter and was found 
    to contain restricted attachments.
    ******************************* WARNING *******************************
    
    ----------------------------------------------------------------------
    Attachment(s) removed
    ----------------------------------------------------------------------
    $LIST_ATTACHMENTS_REMOVED$

    I would like to make this notification look more user-friendly, preferably as an HTML email (with colors, a logo, and a structured table listing the removed attachments).

    Something like this:

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <title>Restricted Attachments Warning</title>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!--
        # This template is used by the content filter
        # Note: lines beginning with # are comments
        -->
      </head>
      <body style="margin:0;padding:0;background-color:#f6f7f9;">
        <!-- Preheader (hidden in most clients) -->
        <div style="display:none;max-height:0;overflow:hidden;opacity:0;color:transparent;">
          The message was scanned by MDaemon's Content Filter and restricted attachments were removed.
        </div>
    
        <table role="presentation" cellpadding="0" cellspacing="0" width="100%" style="background-color:#f6f7f9;margin:0;padding:24px 0;">
          <tr>
            <td align="center" style="padding:0 12px;">
              <table role="presentation" cellpadding="0" cellspacing="0" width="100%" style="max-width:640px;background:#ffffff;border-radius:8px;overflow:hidden;border:1px solid #e5e7eb;">
                <!-- Header / Banner -->
                <tr>
                  <td style="background:#b91c1c;color:#ffffff;padding:16px 20px;text-align:center;font-family:Arial,Helvetica,sans-serif;font-size:18px;font-weight:bold;letter-spacing:0.2px;">
                    ⚠️ WARNING — Restricted Attachments Detected
                  </td>
                </tr>
    
                <!-- Body -->
                <tr>
                  <td style="padding:20px 20px 4px 20px;font-family:Arial,Helvetica,sans-serif;color:#111827;">
                    <p style="margin:0 0 12px 0;font-size:16px;line-height:1.5;">
                      The message has been scanned by <strong>MDaemon's Content Filter</strong> and was found to contain
                      <strong>restricted attachments</strong>. Those attachments have been removed for security reasons.
                    </p>
                  </td>
                </tr>
    
                <!-- Callout -->
                <tr>
                  <td style="padding:0 20px 16px 20px;">
                    <div style="background:#fff7ed;border:1px solid #fdba74;border-radius:6px;padding:12px 14px;font-family:Arial,Helvetica,sans-serif;color:#7c2d12;font-size:14px;line-height:1.45;">
                      If you believe this was a mistake, please contact your mail administrator and reference the original message details.
                    </div>
                  </td>
                </tr>
    
                <!-- Section Title -->
                <tr>
                  <td style="padding:6px 20px 0 20px;font-family:Arial,Helvetica,sans-serif;">
                    <hr style="border:none;border-top:1px solid #e5e7eb;margin:0 0 12px 0;">
                    <h2 style="margin:0 0 8px 0;font-size:15px;line-height:1.4;color:#374151;font-weight:700;letter-spacing:0.2px;">
                      Attachment(s) Removed
                    </h2>
                    <p style="margin:0 0 8px 0;font-size:13px;line-height:1.5;color:#4b5563;">
                      The following attachments were removed by the filter:
                    </p>
                  </td>
                </tr>
    
                <!-- Attachments List (MDaemon placeholder) -->
                <tr>
                  <td style="padding:0 20px 16px 20px;">
                    <!-- If $LIST_ATTACHMENTS_REMOVED$ renders as plain lines, wrapping in <pre> keeps layout tidy -->
                    <pre style="margin:0;background:#f3f4f6;border:1px solid #e5e7eb;border-radius:6px;padding:12px;font-family:Consolas,Menlo,Monaco,monospace;font-size:12px;line-height:1.5;color:#111827;white-space:pre-wrap;word-wrap:break-word;">
    $LIST_ATTACHMENTS_REMOVED$
                    </pre>
                  </td>
                </tr>
    
                <!-- Footer -->
                <tr>
                  <td style="padding:16px 20px 20px 20px;font-family:Arial,Helvetica,sans-serif;color:#6b7280;font-size:12px;line-height:1.5;text-align:center;">
                    This notification was generated automatically by Mail Server. Do not reply to this message.
                  </td>
                </tr>
              </table>
    
              <!-- Small meta note -->
              <div style="max-width:640px;color:#9ca3af;font-family:Arial,Helvetica,sans-serif;font-size:11px;line-height:1.5;padding:8px 0;">
           
              </div>
            </td>
          </tr>
        </table>
      </body>
    </html>
    

    Is there a way to configure MDaemon to send this content as HTML instead of plain text — either by editing the template file or through another mechanism?



  • The content of the CFAttachwrn.dat file can only be in plain text. 

    There is a content filter action that you can use to insert an HTML warning, however, the only way I found to detect the message with a content filter rule is to use the condition for "If the Message contains a file called".  This problem with doing this is that you'd then need a content filter rule for each entry in the restricted attachments list.  This is not ideal, but the rule would look something like this:

    [Rule047]
    RuleName=Restricted Attachment Warning
    uid={871dc5d1-57c8-44d0-9df6-94da015966da}
    Enable=No
    ThisRuleCondition=All
    ProcessQueue=BOTH
    Condition01=body|attachment name|AND|.PNG
    Action01=extract attachments|"0","*.PNG","c:\mdaemon\cfilter\quarant","1"
    Action02=add warning html|"<div style="border:solid;background:#FFEB9C;">","<p style="line-height:12.0pt;margin-left:auto;margin-right:auto;width:98%"><span style="font-size:10.0pt;color:red">CAUTION: </span>The message has been scanned by <strong>MDaemon's Content Filter</strong> and was found to contain","                  <strong>restricted attachments</strong>. Those attachments have been removed for security reasons.","The following attachments were removed by the filter:</p>","","$LIST_ATTACHMENTS_REMOVED$","</div>"

    We'll look into improving the functionality for a future version.


  • We've made changes to MDaemon 26 so that a custom X header will always be added when a message is found to have restricted attachments.  This change should make it easier to use the content filter to add a custom HTML warning to the message.


Please login to reply this topic!