[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 - appending msg to txt file

appending msg to txt file

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

appending msg to txt file

Postby janrif » Tue Feb 22, 2005 12:56 pm

I have filter set for outgoing msgs to move to PM archive based on date, i.e. 2005 --> Archive | Sent 2005 mailbox.

I would also like to save these msgs to appended txt file. I found send to file but don't know what happens to msg 2... overwrite or append?

TIA

--
Jan Rifkinson
Ridgefield, CT USA
ICQ 41116329
skype janrif
janrif
Ridgefield, CT USA
w2k-sp4
janrif
Resident Poster
 
Posts: 111
Joined: Mon Aug 30, 2004 11:53 pm
Location: CT, USA

Postby Michael » Tue Feb 22, 2005 2:55 pm

Jan, if you are talking about the PocoScript SaveMessageToFile command then it will overwrite the file unless you first use the AppendToFile command. E.g.,
Code: Select all
AppendToFile True
SaveMessageToFile %message "C:/Temp/File.txt"
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Postby janrif » Wed Feb 23, 2005 1:53 am

Michael wrote:Jan, if you are talking about the PocoScript SaveMessageToFile command then it will overwrite the file unless you first use the AppendToFile command. E.g.,
Code: Select all
AppendToFile True
SaveMessageToFile %message "C:/Temp/File.txt"


Michael, Thanks for your post. This is what I have in my save to text script

ReadBody $body %message
AssignBody %message $body
SaveMessageToFile %message "path\to\my\eml\file.eml"

A couple of things.
1. Is this script ok for what I want to do if I include the append line?
2. Is it possible to save file as text rather than eml?
3. Do I need to create the file first or will pcoo create the file for me first time out?

TIA

Edit Eric: Moved to PocoScript
janrif
Ridgefield, CT USA
w2k-sp4
janrif
Resident Poster
 
Posts: 111
Joined: Mon Aug 30, 2004 11:53 pm
Location: CT, USA

Postby Michael » Wed Feb 23, 2005 2:09 am

janrif wrote:
Michael wrote:Jan, if you are talking about the PocoScript SaveMessageToFile command then it will overwrite the file unless you first use the AppendToFile command. E.g.,
Code: Select all
AppendToFile True
SaveMessageToFile %message "C:/Temp/File.txt"


Michael, Thanks for your post. This is what I have in my save to text script

ReadBody $body %message
AssignBody %message $body
SaveMessageToFile %message "path\to\my\eml\file.eml"

A couple of things.
1. Is this script ok for what I want to do if I include the append line?


Tio make this script append to the file rather than overwrite it insert the AppendToFile command before the SaveMessageToFile command. (e.g., "AppendToFile True").

janrif wrote:2. Is it possible to save file as text rather than eml?


Yes, you could write this to a text file rather than an eml file, simply change the extenstion to ".txt" but see also my comments below.

The script the way it is written is playing with the message itself. The only change it is making to the message is converting a styled message to plain text. It is not removing any attachments so, if you are keeping attachments encoded in the message then they may be corrupted in the copy of the message you are saving to disk (the attachment in the original message in your Poco mailbox will still be ok).

janrif wrote:3. Do I need to create the file first or will pcoo create the file for me first time out?


Poco will crate the file if it odes not exist.
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Postby janrif » Wed Feb 23, 2005 3:03 am

want to insert a line separator between msgs. Thought $appendbody $a%b might work but can't figure the syntax out. Also don't understand something else. Scripts inclulde separate $header commands which I would like to use to replace headers as supplied in the %messasge script but I would have thought the messagebody was just that -- not with headers -- but that doesn't seem to be the case. So what command should I use for just msg body? And Thanks re: txt vs eml explanation.

this is what I'd like my file to look like

To:
Date:
Subject:

message body

line separator

To:
Date:
Subject:

message body

Thanks,
Jan
janrif
Ridgefield, CT USA
w2k-sp4
janrif
Resident Poster
 
Posts: 111
Joined: Mon Aug 30, 2004 11:53 pm
Location: CT, USA

Postby Michael » Wed Feb 23, 2005 3:35 am

janrif wrote:want to insert a line separator between msgs. Thought $appendbody $a%b might work but can't figure the syntax out.


If by "line separator" you mean a blank line I would add the following line to the script immediately following the ReadBody command.
Code: Select all
AppendBody $Body "\n"
"\n" is an escape sequence for new line. Here is a link to other escape sequences I am aware of.

janrif wrote:Also don't understand something else. Scripts inclulde separate $header commands which I would like to use to replace headers as supplied in the %messasge script but I would have thought the messagebody was just that -- not with headers -- but that doesn't seem to be the case. So what command should I use for just msg body? And Thanks re: txt vs eml explanation.

this is what I'd like my file to look like

To:
Date:
Subject:

message body

line separator

To:
Date:
Subject:

message body

Thanks,
Jan


The messagebody does just contain the body, the problem you are having is that you are using the pre-existing message variable rather than creating a new message variable in the script. As such this message variable contains all the headers from the original message. You need to use the "CreateMessage" command to create a new message variable and then use other commands to copy the Date, Subject and To headers. E.g.,
Code: Select all
CreateMessage %m
ReadHeader $Subject "Subject" %message
AddHeader %m "Subject" $Subject
ReadHeader $Date "Date" %message
AddHeader %m "Date" $Date
ReadTo $To %Message
AddTo %m $To


Notes:
  1. I cannot recall using the ReadTo followed by AddTo combination. It should work but be sure to test this.
  2. Remember to change the other references to the %message variable to %m as appropriate. If you are referencing the message as it exists in your mailbox use %message, if you are referencing the message as you want to save it to the file use %m
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada

Postby janrif » Wed Feb 23, 2005 4:10 am

I understand the concept -- create the message, then tell poco what parts of the msg you want in %m. This is the script now. %message = info from msg in mailbox "sent"

|---------------------------[ Start ] -------------------------|
AppendToFile True

CreateMessage %m
ReadHeader $Subject "Subject" %message
AddHeader %m "Subject" $Subject
ReadHeader $Date "Date" %message
AddHeader %m "Date" $Date
ReadHeader $To "To" %message
AddHeader %m "To" $To

AppendBody $Body "\n"

SaveMessageToFile %message "C:\Documents and Settings\Jan Rifkinson\My Documents\Email Archive\poco_mail_2005\poco_2005.txt"

|-------------------------- [ End ] --------------------------|

But the result of this is From = <>, Full headers from the original msg, no space & no dividing line between msgs.

I'm sure I'm doing something wrong but don't know what it is.

TIA
Jan
janrif
Ridgefield, CT USA
w2k-sp4
janrif
Resident Poster
 
Posts: 111
Joined: Mon Aug 30, 2004 11:53 pm
Location: CT, USA

Postby Michael » Wed Feb 23, 2005 6:51 pm

janrif wrote:...the result of this is From = <>, Full headers from the original msg, no space & no dividing line between msgs.

I'm sure I'm doing something wrong but don't know what it is.

TIA
Jan


Three things seem to be lacking/incorrect.

First you are still saving the original message to the file, not the new one. Change the line:
Code: Select all
SaveMessageToFile %message "C:\Documents and Settings\Jan Rifkinson\My Documents\Email Archive\poco_mail_2005\poco_2005.txt"
to
Code: Select all
SaveMessageToFile %m "C:\Documents and Settings\Jan Rifkinson\My Documents\Email Archive\poco_mail_2005\poco_2005.txt"


Second, to save the from line you need to copy it from the original message and save it to the new one. Use the following code for this:
Code: Select all
ReadHeader $From "From" %Message
AddHeader %m "From" $From


Finally, although you extract the body from the original message you never assign it to the new one. Add the following line immediately after the AppendBody line:
Code: Select all
AssignBody %m $body
Michael
Moderator
 
Posts: 866
Joined: Mon Jul 26, 2004 12:14 pm
Location: Victoria BC, Canada


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 2 guests

cron