Example #1
0
 public void DeleteMessage(IList <UniqueId> uids)
 {
     DoOnLock(() => {
         CurrentFolder.AddFlags(uids, MessageFlags.Deleted, null, true);
         CurrentFolder.Expunge();
     });
 }
Example #2
0
 private void FilesDropped(string[] obj)
 {
     if (IsFolderOpened())
     {
         CurrentFolder.AddRange(obj);
     }
 }
Example #3
0
        public List <string> DownloadThenSaveAttachments(IMessageSummary message, string directory, Action <Exception> onException)
        {
            if (!CreateDirectoryIfNeeded(directory, onException))
            {
                return(null);
            }
            var output = new List <string>();

            DoOnLock(() => {
                foreach (var attachment in message.Attachments)
                {
                    MimeEntity entity = null;
                    try {
                        entity = CurrentFolder.GetBodyPart(message.UniqueId, attachment);
                    } catch (Exception e) {
                        _config.Tracer?.TraceError($"Failed to save attachment an attachment - {e}", $"{this}");
                        onException?.Invoke(e);
                    }

                    if (entity == null)
                    {
                        continue;
                    }
                    var path = PersistMimeEntity(entity, directory, onException);
                    if (!string.IsNullOrEmpty(path))
                    {
                        output.Add(path);
                    }
                }
            });
            return(output);
        }
Example #4
0
        private bool ConnectAndAuthenticate()
        {
            try {
                // connexion and authentication
                Client = Factory.GetImapClient();
                _config.Tracer?.TraceVerbose($"Connected and authenticated successfully", $"{this}");

                CurrentFolder.Open(FolderAccess.ReadWrite);
                _config.Tracer?.TraceVerbose($"Inbox opened", $"{this}");
            } catch (Exception e) {
                if (!_anthenticatedSuccessfully)
                {
                    // we never authenticated successfully, probably a credential error
                    throw new Exception($"{this}: authentication failed (credential error?)", e);
                }

                if (Client?.IsConnected ?? false)
                {
                    _config.Tracer?.TraceError($"Authentication failed - {e}", $"{this}");
                }
                else
                {
                    _config.Tracer?.TraceError($"Connection failed - {e}", $"{this}");
                }

                return(false);
            }

            return(true);
        }
        public IFileWriter this[string filePath]
        {
            get
            {
                if (Disposed)
                {
                    throw new ObjectDisposedException(nameof(FileCollectionWriter));
                }

                filePath = Path.GetFullPath(Path.Combine(CurrentFolder.ToPlatformSpecificPath(),
                                                         filePath.ToPlatformSpecificPath()));

                if (!Files.TryGetValue(filePath, out IFileWriter fileWriter))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(filePath));

                    Logger.WriteInfo($"Writing to {filePath}.");

                    fileWriter = new FileWriter(filePath)
                    {
                        OutputSettings = new OutputSettings
                        {
                            IndentString = Settings.IndentString
                        }
                    };

                    Files.Add(filePath, fileWriter);
                }

                return(fileWriter);
            }
        }
Example #6
0
 public void SendNoOpCommand()
 {
     DoOnLock(() => {
         CurrentFolder.Close();
         CurrentFolder.Open(FolderAccess.ReadWrite);
         _config.Tracer?.TraceVerbose($"NoOp command sent", $"{this}");
     });
 }
Example #7
0
        protected override void BuildXml()
        {
            if (!CurrentFolder.CheckAcl(AccessControlRules.FileView))
            {
                ConnectorException.Throw(Errors.Unauthorized);
            }

            // Map the virtual path to the local server path.
            string sServerDir  = CurrentFolder.ServerPath;
            bool   bShowThumbs = Request.QueryString["showThumbs"] != null && Request.QueryString["showThumbs"].ToString().Equals("1");

            // Create the "Files" node.
            XmlNode oFilesNode = XmlUtil.AppendElement(ConnectorNode, "Files");

            var oDir = new DirectoryInfo(sServerDir);

            FileInfo[] aFiles = oDir.GetFiles();

            for (int i = 0; i < aFiles.Length; i++)
            {
                FileInfo oFile      = aFiles[i];
                string   sExtension = Path.GetExtension(oFile.Name);

                if (Config.Current.CheckIsHiddenFile(oFile.Name))
                {
                    continue;
                }

                //if ( !this.CurrentFolder.ResourceTypeInfo.CheckExtension( sExtension ) )
                //    continue;

                Decimal iFileSize = Math.Round((Decimal)oFile.Length / 1024);
                if (iFileSize < 1 && oFile.Length != 0)
                {
                    iFileSize = 1;
                }

                // Create the "File" node.
                XmlNode oFileNode = XmlUtil.AppendElement(oFilesNode, "File");
                XmlUtil.SetAttribute(oFileNode, "name", oFile.Name);
                XmlUtil.SetAttribute(oFileNode, "date", oFile.LastWriteTime.ToString("yyyyMMddHHmm"));
                if (Config.Current.Thumbnails.Enabled &&
                    (Config.Current.Thumbnails.DirectAccess || bShowThumbs) &&
                    ImageTools.IsImageExtension(sExtension.TrimStart('.')))
                {
                    bool bFileExists = File.Exists(Path.Combine(CurrentFolder.ThumbsServerPath, oFile.Name));
                    if (bFileExists)
                    {
                        XmlUtil.SetAttribute(oFileNode, "thumb", oFile.Name);
                    }
                    else if (bShowThumbs)
                    {
                        XmlUtil.SetAttribute(oFileNode, "thumb", "?" + oFile.Name);
                    }
                }
                XmlUtil.SetAttribute(oFileNode, "size", iFileSize.ToString(CultureInfo.InvariantCulture));
            }
        }
Example #8
0
        public IList <IMessageSummary> GetFullMessagesSummaries(IList <UniqueId> uids)
        {
            IList <IMessageSummary> messages = null;

            DoOnLock(() => {
                messages = CurrentFolder.Fetch(uids, MessageSummaryItems.Full | MessageSummaryItems.BodyStructure);
            });
            return(messages ?? new List <IMessageSummary>());
        }
Example #9
0
        public MimeMessage DownloadMimeMessage(UniqueId uid)
        {
            MimeMessage message = null;

            DoOnLock(() => {
                message = CurrentFolder.GetMessage(uid);
            });
            return(message);
        }
Example #10
0
        public int Count()
        {
            int count = -1;

            DoOnLock(() => {
                CurrentFolder.Check(); // needed to update the folder mail count
                count = CurrentFolder.Count;
            });
            return(count);
        }
        private async Task <StorageFile> GetOrCreateFileAsync(string name)
        {
            var file = await GetFileAsync(name);

            if (file == null)
            {
                file = await CurrentFolder?.TryCreateFileAsync(name);
            }
            return(file);
        }
Example #12
0
        private void DeleteFiles(IList obj)
        {
            List <string> files = new List <string>(obj.Count);

            files.AddRange(obj.Cast <string>());

            foreach (var file in files)
            {
                CurrentFolder.Remove(file);
            }
        }
        public override async Task <bool> TryGoUpAsync(Frame frame)
        {
            var parent = await CurrentFolder.GetParentAsync();

            if (parent != null)
            {
                frame.Navigate(typeof(LocalFolderPage), new LocalFolderViewModel(parent, Path?.Parent?.Parent));
                return(true);
            }

            return(false);
        }
Example #14
0
        public IList <UniqueId> GetUis()
        {
            IList <UniqueId> list = null;

            DoOnLock(() => {
                // FYI, this is equivalent (but faster/less consuming than) to
                // var fetch = folder.Fetch(min, -1, MailKit.MessageSummaryItems.UniqueId);
                list = CurrentFolder.Search(SearchQuery.All);
                // ex of another query : CurrentFolder.Search(SearchQuery.DeliveredAfter(deliverAfter));
            });
            return(list ?? new List <UniqueId>());
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
                if (_Bw != null)
                {
                    _Bw.Dispose();
                    _Bw = null;
                }

                if (CurrentFolder != null)
                {
                    CurrentFolder.Dispose();
                    CurrentFolder = null;
                }
                if (_SelectionTimer != null)
                {
                    _SelectionTimer.Dispose();
                    _SelectionTimer = null;
                }
                if (_Small != null)
                {
                    _Small.Dispose();
                    _Small = null;
                }
                if (_ResetEvent != null)
                {
                    _ResetEvent.Dispose();
                    _ResetEvent = null;
                }
                if (_ResetTimer != null)
                {
                    _ResetTimer.Dispose();
                    _ResetTimer = null;
                }
                if (_KeyJumpTimer != null)
                {
                    _KeyJumpTimer.Dispose();
                    _KeyJumpTimer = null;
                }
                if (_Kpreselitem != null)
                {
                    _Kpreselitem.Dispose();
                    _Kpreselitem = null;
                }
            }
            base.Dispose(disposing);
        }
Example #16
0
        private void AddFiles()
        {
            var openFileDialog = new System.Windows.Forms.OpenFileDialog
            {
                Filter      = "All files|*.*",
                Multiselect = true
            };

            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                CurrentFolder.AddRange(openFileDialog.FileNames);
            }
        }
Example #17
0
 private void cmdUp_Click(object sender, RoutedEventArgs e)
 {
     string[] dirs = CurrentFolder.Split(new char[] { System.IO.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries);
     if (dirs.Length > 1)
     {
         string newf = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), dirs, 0, dirs.Length - 1);
         if (dirs.Length == 2)
         {
             newf += System.IO.Path.DirectorySeparatorChar;
         }
         CurrentFolder = newf;
     }
 }
Example #18
0
 private void LoadFolder(VirtualFolder obj)
 {
     if (obj != null)
     {
         if (obj.Name != SelectedFolder && _changed == true)
         {
             UpdateVirtualFolder();
         }
         CurrentFolder.UpdateWith(obj.Files);
         SelectedFolder = obj.Name;
         _changed       = false;
     }
 }
Example #19
0
        private async Task TryGetSubFolders(bool withSecond)
        {
            if (_isLoading || _isLoaded)
            {
                return;
            }
            _isLoading = true;
            var subFolders = await CurrentFolder.GetFoldersAsync();

            SubFolders.AddAll(subFolders.Select(it => new TreeViewItemModel(it, withSecond)));
            _isLoaded  = true;
            _isLoading = false;
        }
Example #20
0
        public void MoveMessagesToInboxSubFolder(IList <UniqueId> uids, string folder)
        {
            DoOnLock(() => {
                IMailFolder destFolder;
                try {
                    destFolder = CurrentFolder.GetSubfolder(folder);
                } catch (FolderNotFoundException) {
                    destFolder = CurrentFolder.Create(folder, true);
                }

                CurrentFolder.MoveTo(uids, destFolder);
            });
        }
 protected void UpdateList()
 {
     OAuthUtility.GetAsync
     (
         "https://api.dropbox.com/1/metadata/auto/",
         new HttpParameterCollection
     {
         { "path", CurrentFolder.Replace("\\", "/") },
         { "access_token", Properties.Settings.Default.token }
     },
         callback: (RequestResult result) => Application.Current.Dispatcher.Invoke(DispatcherPriority.Background,
                                                                                   new Action(() => UpdateList_Result(result)))
     );
 }
Example #22
0
        public string GetFullPath(string path)
        {
            if (CurrentFolder.IsNotEmpty())
            {
                path = string.Concat(CurrentFolder, "/", path);
            }
            var assetFile = _assetPipeline.Find(path);

            if (assetFile == null)
            {
                return(null);
            }
            return(assetFile.FullPath);
        }
        /// <summary>
        /// AdjustFolderToTree
        /// CurrentFolder comes in format site/lists/listName/folderName for example
        /// /Team/Lists/Tasks/2008 in order to search in the tree we need remove
        /// the site and list for lists and the first slash for document libraries
        /// For doc libs we nees Shared Documents/Folder and the CurrentFolder contains
        /// /site/Shared Documents/Folder
        /// </summary>
        /// <returns>
        /// The relative list path used to find a node in a tree
        /// </returns>
        private string AdjustFolderToTree()
        {
            string pathToRemove = SPContext.Current.Web.ServerRelativeUrl;

            if (ListIsDocumentLibrary)
            {
                pathToRemove += SLASH;
            }
            else
            {
                pathToRemove += SLASH + "Lists" + SLASH;
            }

            return(CurrentFolder.Replace(pathToRemove, string.Empty));
        }
        private async void fromURLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FormInputDialog dialog = new FormInputDialog("Upload from URL", "Type the URL to save to this folder in OneDrive:");
            var             result = dialog.ShowDialog();

            if (result != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            Uri remoteUrl = new Uri(dialog.InputText);
            var filename  = System.IO.Path.GetFileName(remoteUrl.AbsolutePath);
            var job       = await Connection.UploadFromUrlAsync(CurrentFolder.ItemReference(), dialog.InputText, filename);

            JobStatusForm.PendingJobs.Add(job);
            ShowJobStatus();
        }
        /// <summary>
        /// Generates the bread crumb.
        /// </summary>
        private void GenerateBreadCrumb()
        {
            string[] paths        = CurrentFolder.Split(SLASH);
            string   fullPath     = string.Empty;
            int      contextStart = GetCurrentWebLevel();
            int      start        = contextStart;

            if (paths.Length > MaxLevels + contextStart)
            {
                start = paths.Length - MaxLevels;
            }

            for (int i = 1; i < start && i < paths.Length; i++)
            {
                fullPath += SLASH + paths[i];
            }

            if (paths.Length > MaxLevels + contextStart)
            {
                _html  = GenerateLink(BREADCRUMB_PREVOIUS, fullPath);
                _html += HTML_SPACE;
            }

            for (int i = start; i < paths.Length; i++)
            {
                string path = paths[i];

                fullPath += SLASH + path;

                if (!path.Equals("Lists"))
                {
                    _html += GenerateLink(path, fullPath);

                    if (i != paths.Length - 1)
                    {
                        _html += BREADCRUMB_SEPARATOR;
                    }
                }
            }

            if (_html.Length == 0)
            {
                _html = GenerateLink(paths[paths.Length - 1], fullPath);
            }
        }
Example #26
0
        public virtual void OnNextSort <T>() where T : struct, IConvertible
        {
            CurrentSort++;

            if (CurrentSort > Enum.GetValues(typeof(T)).Length - 1)
            {
                CurrentSort = 0;
            }

            if (CurrentFolder.HasChildren())
            {
                CurrentFolder.Children = SortList(CurrentFolder.Children);
            }
            else
            {
                NestedItems = SortList(NestedItems);
            }
        }
Example #27
0
 public void DownloadThenDoForEachAttachments(IMessageSummary message, Action <string, byte[]> attachmentHandler, Action <Exception> onException)
 {
     DoOnLock(() => {
         foreach (var attachment in message.Attachments)
         {
             try {
                 var entity = CurrentFolder.GetBodyPart(message.UniqueId, attachment);
                 if (entity != null)
                 {
                     DoWithMimeEntity(entity, attachmentHandler, onException);
                 }
             } catch (Exception e) {
                 _config.Tracer?.TraceError($"Failed to get an attachment - {e}", $"{this}");
                 onException?.Invoke(e);
             }
         }
     });
 }
Example #28
0
        public string DownloadBody(IMessageSummary mail)
        {
            string output = null;

            DoOnLock(() => {
                // download the 'text/plain' body part, .Text is a convenience property that decodes the content and converts the result to a string for us
                if (mail.TextBody != null)
                {
                    output = (CurrentFolder.GetBodyPart(mail.UniqueId, mail.TextBody) as TextPart)?.Text;
                }

                if (string.IsNullOrEmpty(output) && mail.HtmlBody != null)
                {
                    output = (CurrentFolder.GetBodyPart(mail.UniqueId, mail.HtmlBody) as TextPart)?.Text;
                }
            });
            return(output);
        }
        /// <summary>
        /// Generates the bread crumb.
        /// </summary>
        private void GenerateBreadCrumb()
        {
            string[] paths        = CurrentFolder.Split('/');
            string   fullPath     = string.Empty;
            int      contextStart = NavigationTools.GetCurrentWebLevel();
            int      start        = contextStart;

            if (paths.Length > MaxLevels + contextStart)
            {
                start = paths.Length - MaxLevels;
            }

            for (int i = 1; i < start && i < paths.Length; i++)
            {
                fullPath += SLASH + paths[i];
            }

            if (paths.Length > MaxLevels + contextStart)
            {
                _html = GenerateLink("... > ", fullPath);
            }

            for (int i = start; i < paths.Length; i++)
            {
                string path = paths[i];

                fullPath += SLASH + path;

                if (!path.Equals("Lists"))
                {
                    _html += GenerateLink(path, fullPath);

                    if (i != paths.Length - 1)
                    {
                        _html += " > ";
                    }
                }
            }

            if (_html.Length == 0)
            {
                _html = GenerateLink(paths[paths.Length - 1], fullPath);
            }
        }
        public MainWindow()
        {
            InitializeComponent();
            _currentFolder = new CurrentFolder();
            Binding cfBinding = new Binding("CFProperty")
            {
                Source = _currentFolder
            };

            BindingOperations.SetBinding(currentFolderTB, TextBox.TextProperty, cfBinding);

            _cardsReadyCount = new CardsReady();
            Binding crBinding = new Binding("CardReadyProperty")
            {
                Source = _cardsReadyCount
            };

            BindingOperations.SetBinding(cardsReadyTB, TextBox.TextProperty, crBinding);
        }