/// <summary> /// Add a new entry /// </summary> /// <param name="item">MMailAttachment1 object item</param> /// <returns>bool type true if file added sucessfully</returns> public bool AddEntry(MAttachmentEntry item) { if (item == null) { return(false); } if (_items == null) { // load data LoadLOBData(); } bool retValue = false; try { _items.Add(item); retValue = true; } catch { } log.Fine(item.ToString()); AddTextMsg(" "); // otherwise not saved return(retValue); }
/// <summary> /// Save Entry Data in Zip File format /// </summary> /// <returns>bool type true if saved</returns> private bool SaveLOBData() { if (_items == null || _items.Count == 0) { // if no items // Set binary data in PO and return SetBinaryData(null); return(true); } ByteArrayOutputStream bOut = new ByteArrayOutputStream(); // initialize zip ZipOutputStream zip = new ZipOutputStream(bOut); zip.setMethod(ZipOutputStream.DEFLATED); zip.setLevel(Deflater.BEST_COMPRESSION); // try { // for every item in list int isize = _items.Count; for (int i = 0; i < isize; i++) { // get item MAttachmentEntry item = GetEntry(i); // make zip entry ZipEntry entry = new ZipEntry(item.GetName()); // set time entry.setTime(long.Parse(System.DateTime.Now.Millisecond.ToString())); entry.setMethod(ZipEntry.DEFLATED); // start setting zip entry into zip file zip.putNextEntry(entry); byte[] data = item.GetData(); object obj = (object)data; // set data into zip zip.write((byte[])obj, 0, data.Length); // close zip entry zip.closeEntry(); } // close zip zip.close(); byte[] sObjData = bOut.toByteArray(); byte[] zipData = ConvertToByte(sObjData); log.Fine("Length=" + zipData.Length); // Set binary data in PO and return SetBinaryData(zipData); return(true); } catch (Exception ex) { log.Log(Level.SEVERE, "saveLOBData", ex); } // Set binary data in PO and return SetBinaryData(null); return(false); }
public MAttachmentEntry[] GetEntries() { if (_items == null) { LoadLOBData(); } MAttachmentEntry[] retValue = new MAttachmentEntry[_items.Count]; retValue = _items.ToArray(); return(retValue); }
/// <summary> /// Saves the file at given index to harddisk at given path /// </summary> /// <param name="index">index</param> /// <param name="filePath">file path</param> public void SaveEntryFile(int index, string filePath) { // get item MAttachmentEntry item = GetEntry(index); // save file if (item != null) { item.SaveFile(filePath); } //return null; }
/// <summary> /// Get file data of the entry at given index /// </summary> /// <param name="index">index</param> /// <returns>byte[] data</returns> public byte[] GetEntryData(int index) { // get item MAttachmentEntry item = GetEntry(index); // get data if (item != null) { return(item.GetData()); } return(null); }
/// <summary> /// Get file name of the entry at given index /// </summary> /// <param name="index">index</param> /// <returns>string</returns> public string GetEntryName(int index) { // get item MAttachmentEntry item = GetEntry(index); // get name if (item != null) { return(item.GetName()); } return(null); }
} // getImage /// <summary> /// Get Data as byte array /// </summary> /// <returns>data or null</returns> public byte[] GetData() { MImage image = GetImage(); if (image != null) { byte[] data = image.GetData(); if (data == null || data.Length == 0) { log.Config("No Image Data"); } } // Attachment MAttachment att = GetAttachment(); if (att == null || att.GetEntryCount() == 0) { log.Config("No Attachment"); return(null); } if (att.GetEntryCount() > 1) { log.Warning(GetName() + " - more then one attachment - " + att.GetEntryCount()); } // MAttachmentEntry entry = att.GetEntry(0); if (entry == null) { log.Config("No Attachment Entry"); return(null); } byte[] buffer = entry.GetData(); if (buffer == null || buffer.Length == 0) { log.Config("No Attachment Entry Data"); return(null); } return(buffer); } // getData