ExtractText

Use external tools to extract text from message attachments, such as images, PDFs, and other document types, based on the file name and MIME type. The external tools must output plain text (not HTML or other non-textual results); the extracted text is then set as the rendered part of the message so SpamAssassin rules can be applied to it.

How it works

The plugin invokes the external tools configured with the extracttext_use setting (which tool to use for which file extensions and MIME types) and the extracttext_external setting (the command to run). Each tool must read the document and write the extracted text to standard output; the {} placeholder in the command is substituted with the temporary file name at runtime.

The amount of work performed is bounded by extracttext_maxparts (the maximum number of MIME parts analyzed, where 0 means all parts) and extracttext_timeout (the timeout in seconds per attachment, plus a maximum total time for all checks). The plugin also adds pseudo headers such as X-ExtractText-Chars, X-ExtractText-Tools, and X-ExtractText-Flags, which can be used in rules and are available as template tags such as _EXTRACTTEXTFLAGS_.

Enable the ExtractText plugin

Login to Plesk and go to Warden Anti-spam and Virus Protection -> Settings -> Plugin Settings check the ExtractText plugin then save the page to enable the plugin. After enabling the plugin don't forget to install the external tools for the document types that you want to scan using the instructions below.

Images

If you would like to extract text from images:

// AlmaLinux / CloudLinux / RHEL / Rocky Linux
yum install tesseract

// Debian / Ubuntu
apt-get install tesseract-ocr

Go to Warden Anti-spam and Virus Protection -> Settings -> Plugin Settings -> ExtractText

Under Extracttext use add the following line:

tesseract .jpg .png .bmp .tif .tiff image/(?:jpeg|png|x-ms-bmp|tiff)

Under Extracttext external add the following line:

tesseract {OMP_THREAD_LIMIT=1} /usr/bin/tesseract -c page_separator= {} -

PDF Documents

If you would like to extract text from pdfs:

// AlmaLinux / CloudLinux / RHEL / Rocky Linux
yum install poppler-utils

// Debian / Ubuntu
apt-get install poppler-utils

Go to Warden Anti-spam and Virus Protection -> Settings -> Plugin Settings -> ExtractText

Under Extracttext use add the following line:

pdftotext .pdf application/pdf

Under Extracttext external add the following line:

pdftotext /usr/bin/pdftotext -nopgbrk -layout -enc UTF-8 {} -

Word Documents

If you would like to extract text from word documents:

// AlmaLinux / CloudLinux / RHEL / Rocky Linux
yum install antiword

// Debian / Ubuntu
apt-get install antiword

Go to Warden Anti-spam and Virus Protection -> Settings -> Plugin Settings -> ExtractText

Under Extracttext use add the following line:

antiword .doc application/(?:vnd\.?)?ms-?word.*

Under Extracttext external add the following line:

antiword /usr/bin/antiword -t -w 0 -m UTF-8.txt {}

RTF Documents

If you would like to extract text from RTF documents:

// Debian / Ubuntu (only)
apt-get install unrtf

Go to Warden Anti-spam and Virus Protection -> Settings -> Plugin Settings -> ExtractText

Under Extracttext use add the following line:

unrtf .doc .rtf application/rtf text/rtf

Under Extracttext external add the following line:

unrtf /usr/bin/unrtf --nopict {}

OpenDocument Documents

If you would like to extract text from OpenDocument documents:

// RHEL / AlmaLinux 9 (only)
yum install odt2txt

// Debian / Ubuntu
apt-get install odt2txt

Go to Warden Anti-spam and Virus Protection -> Settings -> Plugin Settings -> ExtractText

Under Extracttext use add the following lines:

odt2txt .odt .ott application/.*?opendocument.*text
odt2txt .sdw .stw application/(?:x-)?soffice application/(?:x-)?starwriter

Under Extracttext external add the following line:

odt2txt /usr/bin/odt2txt --encoding=UTF-8 {}

Related Pages