Codestone Ltd logo

Reload previously saved messages

// Example: CSMail JScript Example 6
// Summary: Load all the messages we saved in Example 5 
// Usage:   cscript exjs06.js
//          or
//          wscript exjs06.js


// See the Microsoft Windows Scripting Host Documentation for details
// of the FileSystemObject model

fso=new ActiveXObject("Scripting.FileSystemObject");
folder=fso.GetFolder("v:\inbox");
files=new Enumerator(folder.files);             // Need an enumerator object in JScript!

for (; !files.atEnd(); files.moveNext()) {      // Iterate through the files
  
MyMsg=new ActiveXObject("CSMail.Message");    // Create the message object
  
MyMsg.LoadFromFile(files.item().Path);

  
WScript.echo(MyMsg.Subject);        
  
  
for (i=1;i<MyMsg.Sections.Count;i++) {          // Iterate through all the sections
    
section=MyMsg.Sections(i);                    // Possibly easy to do it this way rather than
                                                  // using an enumerator object

    
if (section.Filename!="") {
      
WScript.echo(section.Filename);             // echo the filename
      
section.WriteBodyToFile("v:\\attachments\\"+section.Filename);
                                                  
// Save the attachment in a suitable place
      
}
    }
  }
  
WScript.echo("Done!");