[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 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 - Need some help with modified vacation script

Need some help with modified vacation script

Scripting questions and ideas

Moderators: Eric, Tomas, robin, Michael

Need some help with modified vacation script

Postby spamsmasher » Thu Nov 19, 2009 4:46 am

Hello,

I'm trying to create a script that uses a canned message when run but also attaches or appends the text of the original email. I've modified the vacation script to accomplish most of this, but I'm running into a few issues. I need all of the text of the original email to be appended to the email, including links in HTML. Right now, when an email arrives with a link in it, it will display the link tag but not the link itself. I need the URL to be displayed.

The other way I could accomplish my goal is to just attach the original message to the new email generated by the script. I'm not aware of any way to do this via the Pocoscript references. Is this possible?


One other issue: how do I display a sender name in the from field? Not the email address itself, but the name.

Right now, my modified vacation script contains:

SetHeader %Out "From:" someone@domain.local

I need to set the header so that someone@domain.local appears as John Doe instead of the email address itself.

I appreciate any help!
spamsmasher
Drop-in Visitor
 
Posts: 9
Joined: Thu Nov 19, 2009 4:20 am

Postby MarkB » Thu Nov 19, 2009 7:20 am

Regarding the second issue, try this. Replace these lines from the "Vacation Message" script
Code: Select all
ReadEmail $From
SetHeader %Out "From:" $From

with these
Code: Select all
ReadEmail $t
AddStrings $From "John Doe <" $t ">"
SetHeader %Out "From:" $From


---

Regarding the first issue: You want to attach the selected message? You could try saving the message as a file to a temp folder, then attaching that file to the message that the script is building.

Code: Select all
Set $filename $temppath
AddStrings $filename "poco_bPz2Cm4nVSQLsHx.eml"
AppendToFile False
SaveMessageToFile %message $filename
Wait 2

; ... later

AttachFile %Out $filename


Please let us know how you get along with this.
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Re:

Postby spamsmasher » Thu Nov 19, 2009 9:03 am

MarkB wrote:Regarding the second issue, try this. Replace these lines from the "Vacation Message" script
Code: Select all
ReadEmail $From
SetHeader %Out "From:" $From

with these
Code: Select all
ReadEmail $t
AddStrings $From "John Doe <" $t ">"
SetHeader %Out "From:" $From




This definitely resolves my second issue.

I'll work on the attachment method, but the more I've thought through the scenarios this script is supposed to dealing with, I've concluded that appending the text to the email will probably be the better way to go. The only catch is displaying all the text when appended, including HTML links.

Any way to do this?

I appreciate the help!
spamsmasher
Drop-in Visitor
 
Posts: 9
Joined: Thu Nov 19, 2009 4:20 am

Postby MarkB » Thu Nov 19, 2009 9:40 am

Notice this line in the Vacation Message script:
Code: Select all
ReadBody $OldBody %message

ReadBody extracts a plain-text version of the message body, stripped of HTML niceties.

You might experiment with replacing ReadBody there with ReadRawBody. Add $OldBody to the bottom of $NewBody. Then AssignStyledBody %Out $NewBody. I haven't tested any of that.
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby spamsmasher » Thu Nov 19, 2009 10:07 am

MarkB wrote:Notice this line in the Vacation Message script:
Code: Select all
ReadBody $OldBody %message

ReadBody extracts a plain-text version of the message body, stripped of HTML niceties.

You might experiment with replacing ReadBody there with ReadRawBody. Add $OldBody to the bottom of $NewBody. Then AssignStyledBody %Out $NewBody. I haven't tested any of that.


That included the link this time, but the html is messed up. I'm seeing raw HTML formatting commands within the appended text. Any suggestions?
spamsmasher
Drop-in Visitor
 
Posts: 9
Joined: Thu Nov 19, 2009 4:20 am

Postby MarkB » Thu Nov 19, 2009 10:22 am

Would you mind showing your script? That particular problem should be remediable.
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Re:

Postby spamsmasher » Thu Nov 19, 2009 10:23 am

Instead of worrying about the HTML formatting, is it possible to convert only the body to text including any URL's in HREF tags?
spamsmasher
Drop-in Visitor
 
Posts: 9
Joined: Thu Nov 19, 2009 4:20 am

Re:

Postby spamsmasher » Thu Nov 19, 2009 10:28 am

Here's my script:

{### Vacation Message
{ A bit more sophisticated, this script will reply to an
{ incoming mail, with a pre-saved template. For this
{ script to run unattended, make sure that in the program
{ settings (F7) under Miscellaneous, Send Queued Messages
{ When Checking Mail is checked.

{ Usage: best used on Incoming messages

{ Initialize user settings: }
External $userfile1 "Create message template" "vacation.txt"

AppendToFile True
ReadHeader $Subject "Subject:" %message
CreateMessage %Out
ExtractEmail $Email
AddStrings $From "John Doe <jdoe@domain.invalid>"
SetHeader %Out "From:" $From
SetHeader %Out "To:"somewhere@domain.local
Set $NewSubject "FW: "
AddStrings $NewSubject $Subject
SetHeader %Out "Subject:" $NewSubject

OpenBody $NewBody $UserFile1
ReadRawBody $OldBody %message
QuoteBody $Email
QuoteBody $OldBody
AppendBody $NewBody " "
AppendBody $NewBody $OldBody
AssignStyledBody %Out $NewBody

SaveMessage %Out "e:\temp3.txt"
SaveMessage %Out "Out.mbx"
spamsmasher
Drop-in Visitor
 
Posts: 9
Joined: Thu Nov 19, 2009 4:20 am

Postby MarkB » Thu Nov 19, 2009 11:02 am

QuoteBody was the main problem. The following is your script with a little cleanup. But these replies are never going to look right, I'm afraid.

Code: Select all
{ Initialize user settings: }
External $userfile1 "Create message template" "vacation.txt"

ReadHeader $Subject "Subject:" %message
CreateMessage %Out
SetHeader %Out "From:" "John Doe <jdoe@domain.invalid>"
SetHeader %Out "To:" somewhere@domain.local
Set $NewSubject "FW: "
AddStrings $NewSubject $Subject
SetHeader %Out "Subject:" $NewSubject

;OpenBody $NewBody $UserFile1
Set $NewBody "<p>This is sample reply text.</p>"
AppendBody $NewBody "<hr><hr>"
ReadRawBody $OldBody %message
AppendBody $NewBody $OldBody
AssignStyledBody %Out $NewBody

SaveMessage %Out "Out.mbx"
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby MarkB » Fri Nov 20, 2009 1:57 am

This AssignStyledBody schemozzle was an interesting academic curiosity -- to me -- but I should not have imposed it on you. I am sorry about that.

The problem is a basic deficiency in PocoMail, namely, that it does not preserve HTML when replying to HTML messages. The only truly satisfactory fulfilment of your requirements, I think, will come when Poco corrects that deficiency. In this matter, breath-holding is not recommended. ;)

Attaching the original message to the reply would be a fairly decent stopgap measure if only you could count on the recipient's emailer being configured to display attachments inline and if .eml files were one of the file types that his emailer displays inline. They do in PocoMail; they don't in Windows Mail.
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby spamsmasher » Fri Nov 20, 2009 9:52 am

MarkB wrote:QuoteBody was the main problem. The following is your script with a little cleanup. But these replies are never going to look right, I'm afraid.

Code: Select all
{ Initialize user settings: }
External $userfile1 "Create message template" "vacation.txt"

ReadHeader $Subject "Subject:" %message
CreateMessage %Out
SetHeader %Out "From:" "John Doe <jdoe@domain.invalid>"
SetHeader %Out "To:" somewhere@domain.local
Set $NewSubject "FW: "
AddStrings $NewSubject $Subject
SetHeader %Out "Subject:" $NewSubject

;OpenBody $NewBody $UserFile1
Set $NewBody "<p>This is sample reply text.</p>"
AppendBody $NewBody "<hr><hr>"
ReadRawBody $OldBody %message
AppendBody $NewBody $OldBody
AssignStyledBody %Out $NewBody

SaveMessage %Out "Out.mbx"



This works well for me. So far, the replies have looked perfect with my limited testing.

One last thing... I'm using ExtractEmail to grab the address and assigning it the variable. I later want to reference the variable so that it displays in the message text.

Here's what I've got:

ExtractEmail $Address

Code: Select all
AppendBody $NewBody "<p> My Message Text </p>"
AddendBody $NewBody "<p>This email came from</p>"
AppendBody $NewBody $Address


This isn't inserting the email address. I'm certain I have the syntax wrong. What do I need to do?


Thanks for all your help!
spamsmasher
Drop-in Visitor
 
Posts: 9
Joined: Thu Nov 19, 2009 4:20 am

Postby MarkB » Fri Nov 20, 2009 11:09 am

This works well for me. So far,...

That's amazing.

Regarding ExtractEmail:
Define the variable $Address -- it will look like either "John Doe" <dojo@xxxxxxx.com> or dojo@xxxxxx.com. Then ExtractEmail will extract the email address, dojo@xxxxxx.com, from it. For example,
Code: Select all
ReadHeader $Address "From:" %message
ExtractEmail $Address
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby MarkB » Sat Nov 21, 2009 7:02 am

spamsmasher, you needn't read this post if you don't want to. The subject of using ReadBody with HTML messages came up, and I thought maybe I would include the following comment, a product of bitter experience, in case it can save someone some stress.

Code: Select all
{  ReadBody and HTML messages: ReadBody is supposed to remove HTML tags and
{  return the text. It has two egregious flaws in this regard (v4.8.0.4400).
{  (1) It does not always strip the HTML tags: it does when Content-Type is
{  text/html; it does not when Content-Type is multipart/related.
{  (2) It sometimes strips text as well as tags (e.g., Google News Alerts).
{  The body ends with a CRLF (v4.8.0.4400).
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Postby MarkB » Sat Nov 21, 2009 7:04 am

Do you want a conventional-looking header for the quoted message? You could paste this first bit near the top of your script:
Code: Select all
{  Compose brief headers for the selected message.
{  Return result in the string $h.
{
{  ReadTo and ReadCC return addresses only, stripped of names (v4.8.0.4400):
{  who@zzzz.com   vs.   "Joe Who" <who@zzzz.com>
{  Therefore, the script reads To and CC headers with ReadHeader.
{
{  ReadHeader separates addresses with line breaks and inserts quotation marks
{  around names (v4.8.0.4400). (X-BCC headers do not contain names.)
{  In composing brief headers, the script removes those quotation marks and
{  joins addresses into a single line -- for legibility, for compactness, and
{  to conform to the familiar UI format.
{
IntToChar $qmark 34
ReadHeader $from "From:" %message
Set $h $from
Call StripQuotes
Set $from $h
ReadHeader $subject "Subject:" %message
ReadHeader $date "Date:" %message
ReadHeader $to "To:" %message
Set $h $to
Call JoinLines
Call StripQuotes
Set $to $h
ReadHeader $cc "CC:" %message
Set $h $cc
Call JoinLines
CallStripQuotes
Set $cc $h
Set $h "<p>----- Original Message -----<br>\n"
AddStrings $h "From: " $from "<br>\n"
AddStrings $h "Subject: " $subject "<br>\n"
AddStrings $h "Date: " $date "<br>\n"
AddStrings $h "To: " $to "<br>\n"
If $cc = "" Then SkipCC
AddStrings $h "CC: " $cc "<br>\n"
:SkipCC
AddStrings $h "</p>\n"


And paste this next bit at the bottom (including the word Exit):
Code: Select all
Exit

:JoinLines
{  Joins the lines in the string $h; separates items with a comma plus space.
{  Requires: $h
{  Changes: $h, $t, $jlLine, #jlMax, #jlIndex
{  Lines are indexed 0 to n-1
Set $t ""
LineCount #jlMax $h
Dec #jlMax
Set #jlIndex 0
:JoinLinesLoop
If #jlIndex > #jlMax Then EndJoinLinesLoop
GetLine $jlLine #jlIndex $h
If $jlLine = "" Then ContinueJoinLines
AddStrings $t $jlLine
If #jlIndex = #jlMax Then EndJoinLinesLoop
AddStrings $t ", "
:ContinueJoinLines
Inc #jlIndex
Goto JoinLinesLoop
:EndJoinLinesLoop
Set $h $t
Return

:StripQuotes
{  Removes double quotation marks (") from the string $h.
{  Requires: $h, $qmark
{  Changes: $h, #sqPos
StringPos #sqPos $qmark $h
If #sqPos < 1 Then Return
SubStrings $h $qmark
Goto StripQuotes


Then insert the string $h where you want it. Note that the first fragment defines the variables $from and $subject, so you won't need to do that again.

Edit: Opps. Corrected an error.
Edit, 2009-11-22: Corrected another transcription error.
MarkB
Poco Enthusiast
 
Posts: 217
Joined: Mon Aug 09, 2004 1:31 am
Location: Canada

Re:

Postby spamsmasher » Mon Nov 23, 2009 11:05 am

Thanks for the help. I've accomplished everything I wanted to do.

I'll let you know if I run into any HTML rendering issues, but so far so good.


Thanks again
spamsmasher
Drop-in Visitor
 
Posts: 9
Joined: Thu Nov 19, 2009 4:20 am


Return to PocoScript Help and How-To

Who is online

Users browsing this forum: No registered users and 0 guests

cron