[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4688: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4690: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4691: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4692: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3823)
Poco Forums • View topic - Attachment Remover

Attachment Remover

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Attachment Remover

Postby Pete » Mon Nov 29, 2004 8:02 pm

Code: Select all
{ Script:  Attachment Remover.poc
{ Author:  PJR
{ Revision History:
{    08 Feb 2004 - Initial version.
{    13 Apr 2004 - Show error message if run from "Special" mailbox.
{
{ This is an "All-In-One" script that removes attachments from messages,
{ but keeps the messages.
{
{ If you run this script manually, it will ask you for confirmation to remove
{ each attachment for each of the currently selected messages.  In this mode,
{ the script will not remove any attachment from any message
{ unless you explicitly answer "Yes".
{
{ If you run it automatically (with your Incoming Filters for example), then it
{ will automatically remove all attachments from incoming messages that
{ meet the specified criteria WITHOUT ASKING YOU.
{ By default, the specified criteria is that all attachments will be removed.
{ One way to use this script in such an automatic way would be to create
{ an Incoming filter that searches "From" for "spam-domain.com" and,
{ if true, calls this script to delete all attachments from the message.
{ Or, as another example, if you don't want to receive any attachments
{ from anybody, then change the filter to search "From" for "@".
{
{ In addition to using a filter to limit which messages are affected
{ by the script (as previously described), you can also specify
{ which attachments are removed from these messages based on
{ the filenames and/or the filename extensions of the attachments.
{ You specify these conditions in the script itself
{ rather than in the filter that calls the script (there are more notes on this
{ below).
{
{ Note to PocoScripters:  I am not using the "External" command to let users
{ customize the behavior of the script because, in my opinion, that is not the
{ right tool for the job in this case.  The script uses more complex logic
{ to filter filenames and filename extensions, and it would be sloppier and
{ more difficult to specify these filters in
{ an External variable or External file.  I believe that it would be better to
{ just change the script itself.
{
{ This script will work regardless of whether or not you automatically decode
{ attachments to the Attach folder (via Tools > Options > Encoding Options).
{ If you decode attachments like this, this script will also delete
{ the corresponding disk files.
{
{ Note that this script only deletes attachments from messages that you download
{ to your computer.  In other words, you cannot use this script to delete
{ attachments or messages on the mail server by calling it from a
{ Predownload filter.  This also means that if you configure your anti-virus
{ software to scan incoming messages for viruses and remove infected
{ attachments, then this script might never get the chance to see
{ those attachments.
{
{ In its initial configuration, this script deletes attachments without
{ regard to filenames or extensions.
{ However, you can change the code in the "Filename Filter" subroutine
{ to explicitly include and exclude certain filenames and extensions.
{ The code to change is at the very end of the script.  Look for label FF_MAIN.
{
{ If you do this, then
{ including and excluding specific filenames and extensions only
{ applies when you run the script in "automatic mode" such as if you call it
{ from the Incoming filters.  In "manual mode", it will always present you with
{ *every* attachment and ask for your confirmation before deleting each one.
{ You can make manual mode work based on filenames and extensions if you
{ comment the first statement of subroutine "File Filter".

Set $OnErrorMessage ""
AddStrings $OnErrorMessage "Error in " $pocoScriptName
Set $OnErrorGoTo "POCO_ERROR"

{ Do not run if currently in a "Special" mailbox. }
StringPos #index "System.pocosys" $currentMailbox
If #index ! 0 Then SPECIAL_MAILBOX_ERROR

{ Get list of attachments for message }
ReadAttached $attachmentList %message
LineCount #attachmentListSize $attachmentList
if #attachmentListSize = 0 Then DONE

{ Determine whether user leaves attachments encoded
Set &isEncoded True
ReadHeader $tmp "X-Poco-Attachment:" %message
If $tmp = "" Then ENCODED
Set &isEncoded False

:ENCODED
ReadHeader $subject "Subject:" %message
ChopString $subject 41 999
Set $wasMessageChanged "False"
Set #i -1

{ For each attachment in the message... }
:MAIN_LOOP
Inc #i
If #i = #attachmentListSize Then SAVE
GetLine $attachmentName #i $attachmentList
Call DELETE_ROUTINE
Goto MAIN_LOOP

{ Now save the resulting message if necessary }
:SAVE
If $wasMessageChanged = "False" Then DONE
If #pocoScriptMode ! 5 Then DONE
SaveMessage %message $currentMailbox
DeleteMessage %message

:DONE
Exit

:SPECIAL_MAILBOX_ERROR
Set $tmp ""
AddStrings $tmp "Cannot remove attachments from messages in \"Special\" mailboxes.\n"
AddStrings $tmp "Please run the script from the actual mailbox (e.g. \"In\")"
MessageBox $tmp
Exit

:POCO_ERROR
Exit


{*******************************************************************************
{* Delete Routine
{*******************************************************************************
{* This subroutine deletes the current attachment, but only if all of the
{* criteria are met.
{*
{* This routine uses the global variables (unlike Filename Filter).
{*******************************************************************************
:DELETE_ROUTINE

Set $FF_filename $attachmentName
Call FILENAME_FILTER
If $FF_doDelete = "False" Then Return
If #pocoScriptMode ! 5 Then DELETE_IT
Set $prompt ""
AddStrings $prompt "MESSAGE: " $subject "\n"
AddStrings $prompt "ATTACHMENT: \"" $attachmentName "\"\n"
AddStrings $prompt "Do you want to delete this attachment? %var%"
InputBox $response $prompt "Yes|No"
If $response = "Yes" Then DELETE_IT
Return

:DELETE_IT
Set $wasMessageChanged "True"
DeleteAttached %message $attachmentName
If &isEncoded Then Return
FileExists &doesFileExist $attachmentName
If &doesFileExist Then DELETE_DISK_FILE
Return

:DELETE_DISK_FILE
DeleteFile $attachmentName
Return


{*******************************************************************************
{* Filename Filter
{*******************************************************************************
{* This subroutine determines whether the passed filename meets the criteria
{* for deletion of the attachment.
{*
{* $FF_filename (in/out) This variable should contain the filename (including
{*                       the path and extension) of the current attachment in
{*                       the message.  This subroutine removes the path from
{*                       this variable and converts the remainder to lowercase.
{* $FF_doDelete (out) This variable will be set to "True" if the current
{*                    attachment should be deleted.
{*******************************************************************************
:FILENAME_FILTER

{ When running the script in manual mode, comment the next line if you want to
{ delete attachments based on filename and extension.
{ (In manual mode, you will be prompted for confirmation
{  regardless of this setting.)
If #pocoScriptMode = 5 Then FF_DELETE

{ First, remove the path to the filename }
StringPos #FF_index \ $FF_filename
If #FF_index = 0 Then FF_PARSE_EXTENSION
ChopString $FF_filename 1 #FF_index
Goto FILENAME_FILTER

{ Second, parse the extension }
:FF_PARSE_EXTENSION
Set $FF_extension ""
Lowercase $FF_filename
Set $FF_tmp $FF_filename

:FF_EXTENSION_LOOP
StringPos #FF_index "." $FF_tmp
If #FF_index = 0 Then FF_MAIN
ChopString $FF_tmp 1 #FF_index
Set $FF_extension $FF_tmp
Goto FF_EXTENSION_LOOP

{ Finally, decide whether or not to remove this attachment. }

:FF_MAIN

{ Uncomment any of the following lines or add your own. }
{ Here are examples that check the extension:
{    If $FF_extension = "jpg" Then FF_KEEP
{    If $FF_extension = "pdf" Then FF_KEEP
{    If $FF_extension = ""    Then FF_DELETE
{    If $FF_extension = "bat" Then FF_DELETE
{    If $FF_extension = "exe" Then FF_DELETE
{    If $FF_extension = "scr" Then FF_DELETE
{ Here are examples that check the filename (and extension):
{    If "phrase one" ^ $FF_filename Then FF_DELETE
{    If "phrase two" ^ $FF_filename Then FF_KEEP
{ If no matches were found so far, then use the following default action:
Goto FF_DELETE
{Goto FF_KEEP

:FF_DELETE
Set $FF_doDelete "True"
Return

:FF_KEEP
Set $FF_doDelete "False"
Return
Pete
 

Postby FieldDir121 » Wed Dec 01, 2004 3:01 pm

Pete,

The script removed the file from the test message I sent myself. I would like to delete the message also. How would I do that?

Scott
FieldDir121
Resident Poster
 
Posts: 149
Joined: Mon Aug 02, 2004 5:18 pm

Postby Michael » Wed Dec 01, 2004 3:23 pm

FieldDir121 wrote:Pete,

The script removed the file from the test message I sent myself. I would like to delete the message also. How would I do that?

Scott
Comment out the SaveMessage command as follows:
Code: Select all
{ Now save the resulting message if necessary }
:SAVE
If $wasMessageChanged = "False" Then DONE
If #pocoScriptMode ! 5 Then DONE
{ SaveMessage %message $currentMailbox
DeleteMessage %message
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Postby FieldDir121 » Wed Dec 01, 2004 4:15 pm

Pete,

Commenting the line doesn't seem to have any effect. The message is there while the attached file is not.

Scott
FieldDir121
Resident Poster
 
Posts: 149
Joined: Mon Aug 02, 2004 5:18 pm

Postby Michael » Wed Dec 01, 2004 5:13 pm

FieldDir121 wrote:Pete,

Commenting the line doesn't seem to have any effect. The message is there while the attached file is not.

Scott
Scott:

I suggested the change, not Pete, it's my bad, not his. I suspect you are running this script on incoming messages. The change I suggested was only going to take effect when the script was run against selected messages. To make it take effect for both you also need to comment out the line above:
Code: Select all
{ If #pocoScriptMode ! 5 Then DONE


Caveat: I have not studied the script in detail, it is possible this change won't be what is needed.
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Postby Pete » Wed Dec 01, 2004 6:25 pm

Yes, Michael's right. Change these two lines:
Code: Select all
If #pocoScriptMode ! 5 Then DONE
SaveMessage %message $currentMailbox

To:
Code: Select all
{If #pocoScriptMode ! 5 Then DONE
{SaveMessage %message $currentMailbox
Pete
 

Postby FieldDir121 » Wed Dec 01, 2004 8:02 pm

Michael and Pete,

I wondered about that line. The message is now being deleted along with the extension.

Thank you.

I wanted to see what messages were "deleted" for a few days so I added this line:

SaveMessage %message Temp
DeleteMessage %message

The delete line appears to still be necessary so the message doesn't remain in the mailbox it was originally intended for.

Scott
FieldDir121
Resident Poster
 
Posts: 149
Joined: Mon Aug 02, 2004 5:18 pm

Postby Pete » Wed Dec 01, 2004 9:14 pm

You're exactly right, Scott. I'm glad that it's working for you. PocoScript is my favorite feature of PocoMail. In fact, it's the main reason why I chose PocoMail over the other email clients.
Pete
 

Postby GPF » Thu Dec 02, 2004 7:44 pm

Sorry if this has been asked before.

Is there a way to delete the attachment on the server side?

If not, is there a way to delete an entire message on the server side based on the attachment's extension?

Basically, I just want to delete any email with COM EXE PIF etc attachments.

Thanks!
GPF
New Arrival
 
Posts: 2
Joined: Thu Dec 02, 2004 7:41 pm

Postby Pete » Fri Dec 03, 2004 1:26 am

As far as I know, this is not directly possible with PocoMail (or probably with any POP3 email client) because, as Robin said in another topic, the client doesn't normally "see" the attachments until it downloads the entire message.

However, with that said, some ISPs and/or email providers add headers to a message if it contains one or more attachments.

For example, I just sent a test message with two attachments to my email provider (FastMail.fm). The server added two headers:

X-Attached: one.pdf
X-Attached: two.doc

If your email provider does this for you, then you should be able to create a Pre-Download filter in Pocomail/Barca that searches this header for .scr or whatever and, if found, delete the message on the server.

I think that this is as good as you're going to get. Also, I can't think of any way to delete the attachments on the server yet keep the message itself.
Pete
 

Postby GPF » Fri Dec 03, 2004 4:03 am

Thanks Pete!
GPF
New Arrival
 
Posts: 2
Joined: Thu Dec 02, 2004 7:41 pm

Postby FieldDir121 » Sun Jul 17, 2005 12:58 pm

Pete,

I have had your script running since you originally posted it. I now find I would like to know how many e-mails are actually being trapped by the script.

How would I put the e-mail in a specific e-mail folder instead of deleting or keeping?

Also, is it possible to delete the file while keeping the e-mail?

Having a resettable counter would accomplish the same result if that is easier.

Thank you.

Scott
FieldDir121
Resident Poster
 
Posts: 149
Joined: Mon Aug 02, 2004 5:18 pm

Postby Pete » Mon Jul 18, 2005 8:48 am

Hi Scott,

Starting with the original script, and assuming you want to save these messages in a mailbox called Scott,

change:
Code: Select all
If #pocoScriptMode ! 5 Then DONE
SaveMessage %message $currentMailbox


to:
Code: Select all
{ If #pocoScriptMode ! 5 Then DONE
SaveMessage %message "Scott"


This will keep the original message but without the attachments. I haven't tested this change so you'll probably want to test it first (although this is a minor change to the script).
Pete
 


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 1 guest

cron