User Tools

Site Tools


Attachment Processing Script

(Added in v7.6)

This script has functions to allow message attachments to be altered:

  • NeedsRecode
  • NeedsRewrite
  • GetRename
  • GetContentDispositionLine (added in v7.8)
  • IsLockNeeded
  • RewriteAttachment


function NeedsRecode(filtervariables, attachments_array, mime_structure)

Called when VPOP3 is about to process a message

  • returns True if the Lua script wants to alter any of the attachments of the whole message


function NeedsRewrite(attachmentname, MIMEtype, filtervariables)

Called when VPOP3 is about to process an attachment in a message (Only called if 'NeedsRecode' returned true, or there is some other reason for VPOP3 to process attachments, eg to remove/rename an attachment due to Attachment Filtering)

  • returns True if the Lua script wants to rewrite/rename the attachment


function GetRename(type, attachmentName, MIMEtype, filterVariables)
  • type = MIME or UUENCODE
  • returns two values, the first is the new filename, the second is the new MIME type (eg 'text/plain', 'image/jpeg', etc)


function GetContentDispositionLine(originalContentDispositionLine, type, attachmentName, rewriteSection, MIMEtype, filterVariables)
  • type = MIME
  • rewriteSection = true if the MIME section will be rewritten (eg because of 'NeedsRewrite' function)
  • returns new Content-Disposition MIME header line


function IsLockNeeded(originalFileName, newFileName, originalAttachmentName, MIMEtype)
  • returns True if a critical section is required around the 'RewriteAttachment' function call (so it is not called multiple times in parallel)
function RewriteAttachment(originalFileName, newFileName, originalAttachmentName, MIMEtype, filterVariables)

Called to give the script a chance to rewrite the attachment. The original attachment is stored in the file 'originalFileName'. The script should write the new attachment to 'newFileName'.

Note that whether or not this function alters the attachment, the attachment data in the message is rewritten using Base64 encoding, so if the original attachment was stored using a different encoding (eg Quoted-Printable) then the message will be changed. 'NeedsRewrite' should return False if you want the message to stay unaltered.

  • returns True if the attachment has actually been rewritten. If not, the original one is used.
reference/attachment_processing_script.txt · Last modified: 2022/11/24 09:29 by paul