[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 - Reattaching attachments to messages

Reattaching attachments to messages

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Reattaching attachments to messages

Postby frazmi » Thu Aug 19, 2004 3:29 am

Sometimes it's necessary (or just desired) to reattach an attachment to a message, or to take an attachment that's been detached (stored in the Attachment directory) and embed it back into the original message. This action might be desired by someone trying to export messages from Poco to another client :cry:

I've not found any easy way to do this, so I've developed the following brute-force approach. If someone has a more elegant way, I'll gladly follow it.

The re-embedding is a 2-script process. Here are the steps.
1) User runs $$$FindAttach on a message. This script lets the user select a file from the Attachments directory. The script then modifies the subject line of the message to include the file name, and saves the modified message in a temporary "Holding" mailbox. (Design notes may be found after the scripts.)

2) The user then manually drags the modified messages from "Holding" to "Out" mailbox.

3) User sends queued messages. The script $$$AddAttach is set to fire as an outgoing filter. This script decodes the file to attach, attaches it to the message, and restores the subject line to it's original state.

4) User sets Poco option to leave attachments encoded in the message. (Not strictly necessary, but there's not much point to these scripts otherwise.)

5) User downloads the messages (which were sent to himself/herself). If Poco options are set properly, the newly arrived message will be identical (well, almost) to the old message, except that the attachment will be encoded in the message.

6) User can go back and clean up the original messages (which are still marked with the file to attach).

Please test these scripts thoroughly before relying on them. They work OK on my system, but that's no guarantee that they will work without error on your system.

Code: Select all
{Script: $$$FindAttach
{ Purpose of the script: To help "reattach" attachments to messages
{ Script lets user select a file in the Attachment folder, and
{ inserts the file name into the subject for later processing.
{ (I prefer this approach to using a header, since it's easy
{ to see which messages have been processed.)
{
{ The script places a copy of the message (with new subject)
{ in a "holding mailbox" -- later, the user must manually drag
{ the messages to the Out box. Otherwise, for reasons that are
{ not clear to me, the $$$AddAttach script will not work properly.
{
{ After this script runs, the companion script $$$AddAttach
{ is designed to be run as an outgoing filter.
{
{ Limitations:
{    Only one file can be attached.
{    Existing headers are ignored (which might have attachment info.

IntToChar $QUOTE 34
IntToChar $CR 13
IntToChar $LF 10
AddStrings $CRLF $CR $LF

{ SELECT THE FILE TO BECOME THE ATTACHMENT
DirList $L $attachpath "*.*"
TrimLines $L

LineCount #L $L
IF #L = 0 THEN NoFiles

GetLine $List 0 $L
IF #L = 1 THEN EndLoop
DeleteLine $L 0 1

:Loop
      GetLine $line 0 $L
      AddStrings $list "|" $line
      DeleteLine $L 0 1
      LineCount #l $l
      If #l = 0 Then EndLoop
      GoTo Loop
:EndLoop
InputBox $F "Select file %var%" $list

{ ADD QUOTES TO THE FILE NAME
Set $File $QUOTE
AddStrings $File $attachpath $F $QUOTE

ReadHeader $Subj "Subject" %message
Set $NewSubject "~~~~"
AddStrings $NewSubject $File "~~~~" $Subj
DeleteHeader "Subject" %message
AddHeader %message "Subject" $NewSubject

{ SAVE MESSAGE IN HOLDING TANK
SaveMessage %message "Holding.mbx"

EXIT

:NoFiles
MessageBox "Selected directory has no files to attach."



Code: Select all
{ Script: $$$AddAttach
{ Second part of the dynamic duo. This script is designed to be
{ run only after messages have been processed by $$$FindAttach.
{ Dragging the subject-modified messages from "Holding.mbx" to
{ the Out box gets them ready to send. Send Queued messages then
{ causes this script to fire.
{
{ This script must be set as the target of an outgoing filter.
{
IntToChar $QUOTE 34

ReadHeader $Subj "Subject" %message
StringPos #Tilde "~~~~" $Subj

IF #Tilde ! 1 THEN NoFiles
ChopString $Subj 1 4

StringPos #Tilde "~~~~" $Subj
IF #Tilde = 0 THEN FileError

Set $File $Subj
ChopString $File #Tilde 9999

SubStrings $File $QUOTE
SubStrings $File $QUOTE
MessageBox $File

AttachFile %message $File
DeleteHeader "Delivered-To "%message

DeleteHeader "Subject" %message
AddIntegers #Tilde 3
ChopString $Subj 1 #Tilde
AddHeader %message "Subject" $Subj

EXIT

:FileError
MessageBox "Bad encoding of file in subject. Quitting..."
EXIT

:NoFiles
MessageBox "No files detected to encode. Quitting..."
EXIT


DESIGN NOTES
1) If desired, the subject of the original message could be restored after the message is saved to "Holding.mbx". I chose not to do this in order to make it easy to see which messages have been "processed."

2) For a similar reason, I chose to put the filename in the subject, rather than adding a header to the message.

3) I don't know why it's not possible to just use one script. However, I could not get Poco to attach the file to the outgoing message except by using the rather Byzantine sequence of steps outlined above. Perhaps there's something wrong with my scripts.
frazmi
Poco Enthusiast
 
Posts: 248
Joined: Tue Jul 27, 2004 1:27 am
Location: South Korea

Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 2 guests

cron