-
Notifications
You must be signed in to change notification settings - Fork 96
Mentions Attachments
Gaute Hope edited this page Sep 29, 2015
·
3 revisions
mentions-attachments
--------------------
File: /home/user/.sup/hooks/mentions-attachments.rb
Detects if given message mentions attachments the way it is probable
that there should be files attached to the message.
Variables:
header: a hash of headers. See 'signature' hook for documentation.
body: an array of lines of body text.
Return value:
True if attachments are mentioned.
If attachments are mentioned in the message, sup checks whether an attachment is really attached.
To use this feature, enable it by setting :confirm_no_attachments: true
in config.yaml.
This hook can be used to localize attachment checking.
example:
### mentions-attachments.rb -- check whether the message mentions attachments
## define regex indicating attachments, adding "Anlage" and "anliegend" for German, keeping
# "attachment", "attached" and "attaching" for English
mentions_attachment = /(\battach(ments?|ed|ing|)\b)|(\banlagen?\b)|(\banliegend(e|es|en|er)?)/i
## Checking
# loop through body, return True on first positive match
body.any? { |l| l.fix_encoding! =~ /^[^>]/ && l.fix_encoding! =~ mentions_attachment }