Chapter 3 DynaScript Predefined Objects
The attachment
object
has these methods:
attachment.GetContents( )
Returns the content of the attachment.
String or binary.
This example retrieves a mail piece with an attachment and displays the attachment:
<!--SCRIPT
mlist = new MailList ("mail.sybase.com", "elmo", "dynamo", "elmo@mail.sybase.com ", "dynamo7@dbsrv.sybase.com");
mlistitem = mlist[6];
mlistitem.Retrieve();
attach = mlistitem.attachments[0];
contents = attach.GetContents();
if( attach.GetErrorCode() != 0 ) {
document.WriteLn( "Error: " + attach.GetErrorInfo() );
} else {
document.contentType = attach.mimeType;
document.writeln( contents );
}
mlist.Disconnect();
-->
attachment.GetErrorCode( )
Returns a code representing the last error that occurred.
Integer.
This example retrieves a mail piece with an attachment and displays the attachment:
<!--SCRIPT
mlist = new MailList ("mail.sybase.com", "elmo", "dynamo", "elmo@mail.sybase.com ");
mlistitem = mlist[6];
mlistitem.Retrieve();
attach = mlistitem.attachments[0];
contents = attach.GetContents();
if( attach.GetErrorCode() != 0 ) {
document.WriteLn( "Error: " + attach.GetErrorInfo() );
} else {
document.contentType = attach.mimeType;
document.writeln( contents );
}
mlist.Disconnect();
-->
attachment.GetErrorInfo( )
Returns a string containing a meaningful error message.
String.
This example retrieves a mail piece with an attachment and displays the attachment:
<!--SCRIPT
mlist = new MailList ("mail.sybase.com", "elmo", "dynamo", "elmo@mail.sybase.com ");
mlistitem = mlist[6];
mlistitem.Retrieve();
attach = mlistitem.attachments[0];
contents = attach.GetContents();
if( attach.GetErrorCode() != 0 ) {
document.WriteLn( "Error: " + attach.GetErrorInfo() );
} else {
document.contentType = attach.mimeType;
document.writeln( contents );
}
mlist.Disconnect();
-->
attachment.SaveAsDocument ( document_name [, fail_if_document_exists] )
Saves the content of the attachment as a PowerDynamo
Web site document. If fail_if_document_exists
is
set to true (the default), SaveAsDocument fails if the document
already exists. If set to false the document is overwritten.
Boolean.
This example saves an attachment as a Dynamo document:
<!--SCRIPT
mlist = new MailList ( "mail.sybase.com", "elmo", "dynamo", "elmo@mail.sybase.com" );
mlistitem = mlist[12];
mlistitem.Retrieve();
document.WriteLn( "subject: " + mlistitem.subject );
document.WriteLn( "size: " + mlistitem.size );
document.WriteLn( "body: " + mlistitem.body );
document.WriteLn( "sender: " + mlistitem.sender );
for( i in mlistitem.attachments ) {
attach = mlistitem.attachments[i];
filesave = attach.SaveAsDocument( "g:\\temp\\Dynamo\\file.txt" );
}
if (filesave) {
document.WriteLn( "File has been saved" );
}
document.writeln( mlistitem.attachments );
mlist.Disconnect();
-->
attachment.SaveAsFile ( file_path [, fail if file exists] )
Saves the content of the attachment to the
file system. If fail_if_file_exists
is
set to true (the default), then SaveAsDocument fails if the document
already exists. If set to false, the file is overwritten.
Boolean.
This example retrieves a mail piece and saves the attachments as files:
<!--SCRIPT
mlist = new MailList ( "dbsrv.sybase.com", "dynamo7", "dynamo", "dynamo7@dbsrv.sybase.com" );
num = mlist.count
document.WriteLn("There are " + num + " messages in the mail box");
mlistitem = mlist[12];
mlistitem.Retrieve();
document.WriteLn( "subject: " + mlistitem.subject );
document.WriteLn( "size: " + mlistitem.size );
document.WriteLn( "body: " + mlistitem.body );
document.WriteLn( "sender: " + mlistitem.sender );
for( i in mlistitem.attachments ) {
attach = mlistitem.attachments[i];
filesave = attach.SaveAsFile( "g:\\temp\\Dynamo\\" + att.name );
}
if (filesave) {
document.WriteLn( "It should have worked" );
}
document.writeln( mlistitem.attachments );
mlist.Disconnect();
-->
Copyright © 1999 Sybase, Inc. All rights reserved. |
![]() |