Problem Using Applescript to Read Email Attachment

B

BluesBrother

I'm trying to use Applescript to access email attachments in Entourage
2004. I can get the Attachment object with no problem. However, when I
attempt to get the "file" property of the "attachment" object, like so

set theFile to file of theAttachment

I get the following error:

Microsoft Entourage got an error: Can’t get file of attachment 1
of incoming message id 50670.

I can't figure out what it's complaining about or trying to tell me.
According to the Entourage Dictionary, "file" is a property of
"attachment":

attachment n : every attachment

elements contained by messages, incoming messages, outgoing
messages, draft windows, draft news windows.

properties

name (text, r/o) : the name of the attachment
file type (type, r/o) : the type of file
file creator (type, r/o) : the creator of file
encoding (no encoding/7bit encoding/8bit encoding/binhex/base64/
uuencode/AppleSingle/AppleDouble/quoted printable/
unknown encoding, r/o) : the MIME encoding of the data
file (alias, r/o) : alias to the associated file (if there is
one)
content (text, r/o) : the encoded content (if it has been
encoded)
properties (record) : property that allows setting a list of
properties

Am I doing this wrong? Ultimately, I want to open the attachment file,
modify it, and write the modified file back, effectively replacing the
attachment.

Thanks in advance for any insight you can provide!
 
B

BluesBrother

I don't think a file will actually exist until you double-click the
attachment to open it.


Even if you do get Entourage to create the attachment file on disk,
you'll only be modifying that file on disk.

I think it's important to understand that the file on disk is not the
same entity as the actual file encoded into the message source. I doubt
the Entourage AppleScript interface would give you a way to edit the
file encoded in the message.

--
Note: Please send all responses to the relevant news group. If you
must contact me through e-mail, let me know when you send email to
this address so that your email doesn't get eaten by my SPAM filter.

JR

Hmmm... I was afraid of that (you can't directly modify the
attachment).

Here's the problem I'm trying to solve. Apple's iCal sends an
invitation in the form of an email with an ICS (iCalendar) file
attachment. As nearly as I can tell, this attachment is RFC 2445
compliant, which specifies a technique for "folding" long lines by
breaking them at an arbitrary point and continuing them onto one or
more succeeding lines, each with a leading space in column 1. It
appears that Entourage 2004 can't parse such files because it doesn't
properly handle such line folding. The result is that 1) the text of
the invitation in the email body is not displayed in the email, and 2)
the Accept, Decline, and Tentative links used to respond to the
invitation are not displayed on the email

I submitted this as a bug to Microsoft, and they confirmed that this
"feature" (i.e., handling of folded lines) is "not supported" by
Entourage 2004, but has been corrected in Entourage 2008

As an alternative to upgrading to Entourage 2008 (with the attendant
expense), in Entourage 2004, I'm triggering an AppleScript with a rule
when an iCalendar invitation is received. The script would locate the
ICS file attachment and "fix" it, by removing the folded lines and
concatenating them into a single, long line, which Entourage 2004
appears to be able to handle with no problem.

Sounds like a plan, but alas, if I can't intercept and modify the ICS
file attachment, looks like I'm out of luck.
 
B

Barry Wainwright

As an alternative to upgrading to Entourage 2008 (with the attendant
expense), in Entourage 2004, I'm triggering an AppleScript with a rule
when an iCalendar invitation is received. The script would locate the
ICS file attachment and "fix" it, by removing the folded lines and
concatenating them into a single, long line, which Entourage 2004
appears to be able to handle with no problem.

Sounds like a plan, but alas, if I can't intercept and modify the ICS
file attachment, looks like I'm out of luck.

Save the attachment to the temp directory and 'correct' it there, then open
the corrected file use entourage to read the ICS event in.

--
Barry Wainwright
Microsoft MVP (see <http://www.microsoft.com/mvp/> for details)
Visit the Entourage User¹s Weblog for Hints, tips and troubleshooting
information:
http://www.barryw.net/weblog/
 
B

BluesBrother

Save the attachment to the temp directory and 'correct' it there, then open
the corrected file use entourage to read the ICS event in.

--
Barry Wainwright
Microsoft MVP (see <http://www.microsoft.com/mvp/> for details)
Visit the Entourage User¹s Weblog for Hints, tips and troubleshooting
information:http://www.barryw.net/weblog/

Hi, Barry,

Thanks for the suggestion, but I'm not sure that I understand exactly
"how" this can be done entirely from an AppleScript (i.e.,
automatically) without any manual intervention. The original problem I
encountered (see original post) was that I couldn't obtain a reference
to the physical file that was the ICS attachment; when I attempt to
obtain the "file" property of the attachment object, I get an error.
So how can I read the file, and then write the modified file back in
its place, all in the context of the rule-driven script? I guess that
I can use Entourage to "save" an attachment (?), but it's not clear to
me how to get him to "read" it back in.

As you may have guessed, I'm new to scripting Entourage.

Thanks.
 
B

BluesBrother

Yes, you can save the attachment to disk:

tell app "Microsoft Entourage"
     save the attachments of the current messages in filePathAlias
end tell

You can then use AppleScript to fix that file, and then tell Entourage
to open it. I think that would cause Entourage to open and accept the
event, though I haven't tested it myself.

--
Note: Please send all responses to the relevant news group. If you
must contact me through e-mail, let me know when you send email to
this address so that your email doesn't get eaten by my SPAM filter.

JR

Thanks, JR.

Well, I'm able to save the original ICS attachment to disk, using

save theAttachment in filePathAlias

as you suggested.

And I can "fix" the original file, no problem.

However, try as I might, I can't get the corrected attachment to
effectively replace the original attachment on the email. I tried

delete theAttachment

which does remove the physical attachment from the message. Then,

make new attachment at theMessage with properties
{file:newFilePathAlias, encoding:"quoted printable"}

adds the corrected file as a physical attachment to the message (I can
see it and save and open the new attachment). However, when I do a
View | Source on the message itself, it still appears to contain the
*original* (uncorrected) attachment as a MIME part, but the encoding
has been changed from "quoted printable" to "7-bit ascii".

So it's not clear to me how (or if) I can get Entourage to recognize
the "new" attachment and act on it, instead of the original attachment.
 
B

Barry Wainwright

So it's not clear to me how (or if) I can get Entourage to recognize
the "new" attachment and act on it, instead of the original attachment.

Don't do it by attaching the ics file to a message - just tell Entourage ot
open the ics file:

Tell app "microsoft entourage" to open filepathalias

--
Barry Wainwright
Microsoft MVP (see <http://www.microsoft.com/mvp/> for details)
Visit the Entourage User¹s Weblog for Hints, tips and troubleshooting
information:
http://www.barryw.net/weblog/
 
B

BluesBrother

Exactly.

--
Note: Please send all responses to the relevant news group. If you
must contact me through e-mail, let me know when you send email to
this address so that your email doesn't get eaten by my SPAM filter.

JR

Yeah, I think I'm going to have to punt on this. The original problem
I'm trying to solve is not getting the event on the calendar, but
rather having Entourage correctly display the attendee Accept,
Decline, and Tentatively Accept links when viewing the message (in
Preview) or the Event (i.e., when opening the invitation). Because of
the bug mentioned above, Entourage 2004 does not display these links
when the invitation is sent by iCal 3.0 (Leopard).

[After much investigation, I've concluded that then root issue is that
Entourage 2004 can't handle the combination of 1) CR-LF's used for
line separators in the ICS file, AND 2) folded lines. iCal appears to
be doing both in accordance with RFC 2445, so Entourage appears to be
the culprit. I dumped the meeting.ics file sent by Entourage 2004 when
HE sends an invitation, and the line separators being used are a
single LF, NOT a CR-LF combination as specified by RFC 2445.]

Anyway, as we discussed earlier, the best I can do is save the ICS
attachment to disk, modify it, and open it. However, this doesn't
accomplish my original objective of allowing the recipient to reply to
the invitation (i.e., Accept, Decline, or Tentatively Accept it).
There appears to be no way to modify the source of the message
containing the invitation, and this is what Entourage uses to
recognize and properly display the invitation. So unless I can fix
*that*, I can't solve my problem on the Entourage end.

Thanks for all your help and for bearing with me as a newbie to
scripting Entourage!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top