Esempio n. 1
0
        public MailMsg(EmailMessage msg, string user)
        {
            this._User    = user;
            this._id      = msg.Id.ToString();
            timestamp     = msg.DateTimeSent;
            this._Subject = msg.Subject;
            this._Body    = msg.Body;

            if (msg.HasAttachments)
            {
                //we will add all attachements to a list
                List <Attachement> oList = new List <Attachement>();
                //load all attachements
                msg.Load(new Microsoft.Exchange.WebServices.Data.PropertySet(Microsoft.Exchange.WebServices.Data.EmailMessageSchema.Attachments));
                foreach (Microsoft.Exchange.WebServices.Data.Attachment att in msg.Attachments)
                {
                    if (att is Microsoft.Exchange.WebServices.Data.FileAttachment)
                    {
                        //load the attachement
                        Microsoft.Exchange.WebServices.Data.FileAttachment fileAttachment = att as Microsoft.Exchange.WebServices.Data.FileAttachment;
                        //load into memory stream, seems the only stream supported
                        System.IO.MemoryStream ms = new System.IO.MemoryStream(att.Size);
                        fileAttachment.Load(ms);//blocks some time
                        ms.Position = 0;
                        oList.Add(new Attachement(ms, fileAttachment.Name));
                        ms.Close();
                    }
                }

                /*
                 * foreach (Attachment a in msg.Attachments)
                 * {
                 *  if (a is Microsoft.Exchange.WebServices.Data.FileAttachment)
                 *  {
                 *      FileAttachment fa = a as FileAttachment;
                 *      System.IO.MemoryStream ms=new System.IO.MemoryStream(fa.Size);
                 *      fa.Load(ms);
                 *      oList.Add(new Attachement(ms, fa.Name));
                 *  }
                 * }
                 */
                this._Attachements = oList.ToArray();
                this.attList.AddRange(oList);
            }
        }
 public void DeleteAttachmentException(EmailMessage message, FileAttachment fa)
 {
     message.Attachments.Remove( fa );
 }
 public string CopyAttachmentToAzure(FileAttachment fa)
 {
     throw new NotImplementedException();
 }
Esempio n. 4
0
        public static void SetAttachment(SenseNet.ContentRepository.File file, FileAttachment fileAttachment)
        {
            using (var stream = new MemoryStream())
            {
                fileAttachment.Load(stream);
                stream.Seek(0, SeekOrigin.Begin);

                var binaryData = new BinaryData();
                binaryData.SetStream(stream);
                file.Binary = binaryData;
                file.Save();
            }
        }
 private async TPL.Task<FileHandle> UplaodAttachmentAsync(FileAttachment fileAttachment)
 {
     using (var stream = new MemoryStream())
     {
         //Load the attachment into a file.
         //This call results in a GetAttachment call to EWS.
         fileAttachment.Load(stream);
         stream.Seek(0, SeekOrigin.Begin);
         var attachmentData = new AttachmentData
         {
             Id = fileAttachment.Id,
             Stream = stream,
             FileName = fileAttachment.FileName ?? fileAttachment.Name,
             ContentType = fileAttachment.ContentType
         };
         var uploadFileAsync = await FileUploadService.UploadFileAsync(attachmentData);
         var handle = await GetHandleFromResponse(uploadFileAsync);
         return new FileHandle { Handle = handle, FileName = attachmentData.FileName };
     }
 }
Esempio n. 6
0
        private static void CopyFileFromAttachment(FileAttachment fileAttachment, string backFolderPath)
        {
            Console.WriteLine("Copy file from attachment to (" + Dns.GetHostName() + ") " + backFolderPath);

            Directory.CreateDirectory(backFolderPath);

            fileAttachment.Load(backFolderPath + fileAttachment.Name);
        }