Beispiel #1
0
        /// <summary>
        /// Updates mail data
        /// </summary>
        public void RefreshMail()
        {
            if (AttachedFileList != null)
            {
                AttachedFileList.Clear();
            }

            ObservableCollection <MailHeader> tempMailList = MailHandler.GetMailHeaders(asb.Text);

            //If no mail was found on server, display error dialog
            if (tempMailList == null)
            {
                DisplayErrorDialog("Mail error", "No mail found. Try again!");
            }
            //If mail was found, replace MailHeaderList with the list with new mail and update UI
            else
            {
                if (MailHeaderList != null)
                {
                    MailHeaderList.Clear();
                }

                MailHeaderList = tempMailList;

                Bindings.Update();              //Updates the ListView data

                CurrentMessage             = MailHandler.GetSpecificMail(MailHeaderList[0].UniqueId);
                MailListView.SelectedIndex = 0;
                HandleAttachmentsAsync(CurrentMessage);
                SetContent(CurrentMessage);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Handles event when user clicks the listview - sets the clicked mail´s content to the webview&listview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MailListView_ItemClicked(object sender, ItemClickEventArgs e)
        {
            AttachedFileList.Clear();

            MailHeader msg = (MailHeader)e.ClickedItem;

            CurrentMessage = MailHandler.GetSpecificMail(msg.UniqueId);
            HandleAttachmentsAsync(CurrentMessage);
            SetContent(CurrentMessage);
        }
Beispiel #3
0
        /// <summary>
        /// Converts attachments to AttachedFile(s)
        /// </summary>
        /// <param name="message"></param>
        private async void HandleAttachmentsAsync(MimeMessage message)
        {
            byte[] byteArray;

            //If Attachments is not empty
            if (message.Attachments.Count() != 0)
            {
                AttachedFilesListView.Visibility = Visibility.Visible;

                foreach (var attachment in message.Attachments)
                {
                    var fileName = attachment.ContentDisposition?.FileName ?? attachment.ContentType.Name;

                    byteArray = HelperUtils.ConvertAttachmentToByteArray(attachment);

                    if (byteArray == null)
                    {
                        DisplayErrorDialog("Attachment error", "Error displaying attachments");
                        return;
                    }

                    //Converts byte[] to StorageFile
                    StorageFile storageFile = await HelperUtils.ConvertsToStorageFileAsync(byteArray, fileName);

                    if (storageFile != null)
                    {
                        //Creates new AttachedFile and adds it to AttachedFileList
                        AttachedFileList.Add(new AttachedFile
                        {
                            FileName  = storageFile.Name,
                            Thumbnail = await storageFile.GetThumbnailAsync(ThumbnailMode.ListView)
                        });
                    }
                }
            }
            else
            {
                //Makes the listview invisible, since there are no attachments to show
                AttachedFilesListView.Visibility = Visibility.Collapsed;
            }
        }