Mail::SpamAssassin::Plugin::ExtractText(3pm) | User Contributed Perl Documentation | Mail::SpamAssassin::Plugin::ExtractText(3pm) |
ExtractText - extracts text from documenmts.
loadplugin Mail::SpamAssassin::Plugin::ExtractText
ifplugin Mail::SpamAssassin::Plugin::ExtractText
extracttext_external pdftotext /usr/bin/pdftotext -nopgbrk -layout -enc UTF-8 {} - extracttext_use pdftotext .pdf application/pdf # http://docx2txt.sourceforge.net extracttext_external docx2txt /usr/bin/docx2txt {} - extracttext_use docx2txt .docx application/docx extracttext_external antiword /usr/bin/antiword -t -w 0 -m UTF-8.txt {} extracttext_use antiword .doc application/(?:vnd\.?)?ms-?word.* extracttext_external unrtf /usr/bin/unrtf --nopict {} extracttext_use unrtf .doc .rtf application/rtf text/rtf extracttext_external odt2txt /usr/bin/odt2txt --encoding=UTF-8 {} extracttext_use odt2txt .odt .ott application/.*?opendocument.*text extracttext_use odt2txt .sdw .stw application/(?:x-)?soffice application/(?:x-)?starwriter extracttext_external tesseract {OMP_THREAD_LIMIT=1} /usr/bin/tesseract -c page_separator= {} - extracttext_use tesseract .jpg .png .bmp .tif .tiff image/(?:jpeg|png|x-ms-bmp|tiff) add_header all ExtractText-Flags _EXTRACTTEXTFLAGS_ header PDF_NO_TEXT X-ExtractText-Flags =~ /\bpdftotext_NoText\b/ describe PDF_NO_TEXT PDF without text score PDF_NO_TEXT 0.001 header DOC_NO_TEXT X-ExtractText-Flags =~ /\b(?:antiword|openxml|unrtf|odt2txt)_NoText\b/ describe DOC_NO_TEXT Document without text score DOC_NO_TEXT 0.001 header EXTRACTTEXT exists:X-ExtractText-Flags describe EXTRACTTEXT Email processed by extracttext plugin score EXTRACTTEXT 0.001
endif
This module uses external tools to extract text from message parts, and then sets the text as the rendered part. External tool must output plain text, not HTML or other non-textual result.
How to extract text is completely configurable, and based on MIME part type and file name.
All configuration lines in user_prefs files will be ignored.
Second argument speficies maximum total time for all checks.
The general syntax is
extracttext_use "name" "specifiers"
Examples
extracttext_use antiword .doc application/(?:vnd\.?)?ms-?word.* extracttext_use openxml .docx .dotx .dotm application/(?:vnd\.?)openxml.*?word.* extracttext_use openxml .doc .dot application/(?:vnd\.?)?ms-?word.* extracttext_use unrtf .doc .rtf application/rtf text/rtf
The special keyword "{}" will be substituted at runtime with the temporary filename to be scanned by the external tool.
Environment variables can be defined with "{KEY=VALUE}", these strings will be removed from commandline.
It is required that commandline used outputs result directly to STDOUT.
The general syntax is
extracttext_external "name" "command" "parameters"
Examples
extracttext_external antiword /usr/bin/antiword -t -w 0 -m UTF-8.txt {} - extracttext_external unrtf /usr/bin/unrtf --nopict {} extracttext_external odt2txt /usr/bin/odt2txt --encoding=UTF-8 {}
The plugin adds some pseudo headers to the message. These headers are seen by the bayes system, and can be used in normal SpamAssassin rules.
The headers are also available as template tags as noted below.
Example
The fictional example headers below are based on a message containing this:
Headers
Contains a count of characters that were extracted.
X-ExtractText-Chars: 10970
Contains a count of "words" that were extracted.
X-ExtractText-Chars: 1599
Contains chains of tools used for extraction.
X-ExtractText-Tools: pdftotext openxml_antiword
Contains chains of MIME types for parts found during extraction.
X-ExtractText-Types: application/pdf; application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/ms-word
Contains chains of canonicalized file extensions for parts found during extraction.
X-ExtractText-Extensions: pdf docx
Contains notes from the plugin.
X-ExtractText-Flags: openxml_NoText
Rules
Example:
header PDF_NO_TEXT X-ExtractText-Flags =~ /\bpdftotext_Notext\b/ describe PDF_NO_TEXT PDF without text
2023-04-30 | perl v5.36.0 |