Monday, June 10, 2024

Read Email attachment

Param.attachmentName=pyAttachmentPage.pyAttachNames(1)

Param.attachmentValue=pyAttachmentPage.pyAttachValues(1)


 String baseDir=tools.getSystemSettings().getFSSetting("initialization/explicittempdir", "" , true, false);

String exportPath= tools.getProperty("pxProcess.pxServiceExportPath").getStringValue().replaceAll("file://web:","");

String AbsoluteFilePath=baseDir+exportPath+tools.getParamValue("FileNameUnique")+".zip";

String line="";

boolean success=true;

java.io.DataOutputStream dos = null;

String zipFilePath = tools.getParamValue("ZipFilePath");

int i=0;

//String zipFileFSPath=null;

try

{

  //Create and write contents to ZIP file

  PRFile zipFile = new PRFile(zipFilePath);

  //zipFileFSPath=zipFile.getAbsolutePath();


  String zipContents=tools.getParamValue("attachmentValue");//.replace("\n","").replaceAll("\\s", "");

  tools.getPrimaryPage().getProperty("pyDescription").setValue(zipContents);

  //byte[] decoded = java.util.Base64.getDecoder().decode(zipContents.getBytes(java.nio.charset.StandardCharsets.UTF_8));

  byte[] decoded = java.util.Base64.getMimeDecoder().decode(zipContents);

  java.io.ByteArrayInputStream bais = new java.io.ByteArrayInputStream(decoded);

  

  dos = new java.io.DataOutputStream(new PROutputStream(zipFile));

  dos.write(decoded);            

  dos.close();


  java.util.zip.ZipFile zippFile=new java.util.zip.ZipFile(AbsoluteFilePath);

  java.util.zip.ZipEntry zipEntry = zippFile.getEntry("Snapshot.json");

  java.io.InputStream inputStream = zippFile.getInputStream(zipEntry);

  java.util.Scanner scanner = new java.util.Scanner(inputStream);

  while (scanner.hasNextLine()) 

    line = line + scanner.nextLine();

  

  //java.util.Enumeration ent = zippFile.entries();

  //while(ent.hasMoreElements()) {

  //  i++;

  //}

  inputStream.close();

  zipFile.delete();

}catch(Exception e){

  

}

tools.getPrimaryPage().getProperty("pyTempText").setValue(i);

tools.getPrimaryPage().getProperty("pyLabel").setValue(AbsoluteFilePath);

tools.getPrimaryPage().getProperty("pyNote").setValue(line);

//Read the json file