Example #1
0
 public bool HandleException(COMException comException)
 {
     _tracer.TraceException(comException);
     if (comException.ErrorCode == (unchecked ((int)0x80040600)))
     {
         StandartJobs.MessageBox("MAPI reports internal error that your message storage is corrupted", "Error",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(true);
     }
     else if (comException.ErrorCode == (unchecked ((int)0x8004011C)))
     {
         StandartJobs.MessageBox("MAPI reports internal error that your message storage is not configured", "Error",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(true);
     }
     else if (comException.ErrorCode == (unchecked ((int)0x80040116)))      //MAPI_E_DISK_ERROR
     {
         StandartJobs.MessageBox("MAPI reports internal error that there is hard disk error while reading from message store.", "Error",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(true);
     }
     else if (comException.ErrorCode == (unchecked ((int)0x8004060C)))      //
     {
         StandartJobs.MessageBox("Outlook reports that your message store exceeded the available space.", "Error",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
         return(true);
     }
     return(false);
 }
Example #2
0
        private static void DeleteMessageImpl(string storeId, string entryId, bool DeletedItems)
        {
            Guard.EmptyStringArgument(storeId, "storeId");
            Guard.EmptyStringArgument(entryId, "entryId");
            IEMsgStore msgStore = OutlookSession.OpenMsgStore(storeId);

            if (msgStore != null)
            {
                try
                {
                    msgStore.DeleteMessage(entryId, DeletedItems);
                }
                catch (System.ArgumentException exception)
                {
                    //there is bug in parameteres for IFolder.DeleteMessages. Try to find it
                    _tracer.Trace("There is problem with parameter while deleting message. EntryId = " + entryId);
                    _tracer.Trace("StoreId = " + storeId);
                    _tracer.TraceException(exception);
                    Core.ReportException(exception, ExceptionReportFlags.AttachLog);
                }
                catch (COMException exception)
                {
                    _tracer.TraceException(exception);
                    StandartJobs.MessageBox("Cannot complete deleting mail. Reason: " + exception.Message, "Error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #3
0
        private void OnUnreadItemChangedImpl(IResource emailResource)
        {
            Guard.NullArgument(emailResource, "emailResource");
            if (emailResource.Type != STR.Email)
            {
                return;
            }
            PairIDs messageIDs = PairIDs.Get(emailResource);

            if (messageIDs == null)
            {
                return;
            }

            IResource folder = Mail.GetParentFolder(emailResource);

            if (folder != null && Folder.IsIMAPFolder(folder))
            {
                PairIDs folderIDs = PairIDs.Get(folder);
                if (folderIDs != null)
                {
                    IEFolder mapiFolder = OutlookSession.OpenFolder(folderIDs.EntryId, folderIDs.StoreId);
                    if (mapiFolder != null)
                    {
                        using ( mapiFolder )
                        {
                            try
                            {
                                mapiFolder.SetReadFlags(messageIDs.EntryId, emailResource.HasProp(Core.Props.IsUnread));
                                return;
                            }
                            catch (COMException exception)
                            {
                                if (exception.ErrorCode == (unchecked ((int)0x80040604)))
                                {
                                    StandartJobs.MessageBox("Unspecified error. Can't change unread flag for email.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }
                                Core.ReportException(exception, ExceptionReportFlags.AttachLog);
                            }
                        }
                    }
                }
            }

            IEMessage message = OutlookSession.OpenMessage(messageIDs.EntryId, messageIDs.StoreId);

            if (message != null)
            {
                using ( message )
                {
                    bool unread = emailResource.HasProp(Core.Props.IsUnread);
                    message.SetUnRead(unread);
                    OutlookSession.SaveChanges("Export Read/Unread flag" + emailResource.Id, message, messageIDs.EntryId);
                }
            }
        }
Example #4
0
 private void ShowErrorMessage()
 {
     if (!_shown)
     {
         _shown = true;
         string message = (OutlookSession.Version >= 11) ? cErrorSendReceiveV11 : cErrorSendReceiveVolder;
         StandartJobs.MessageBox(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #5
0
 protected override void ExecuteActionImpl(IResourceList selectedResources)
 {
     foreach (IResource folder in selectedResources.ValidResources)
     {
         if (folder.Id == _lastFolder.Id || Folder.IsDefault(folder) || Folder.IsAncestor(_lastFolder, folder))
         {
             StandartJobs.MessageBox("Cannot move folder '" + folder.DisplayName +
                                     "' to folder '" + _lastFolder.DisplayName + "'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
     }
     new MoveFolderToFolderAction().DoMove(_lastFolder, selectedResources);
 }
Example #6
0
 public override void Execute(IActionContext context)
 {
     Trace.WriteLine(">>> Executing OutlookAction");
     try
     {
         base.Execute(context);
     }
     catch (COMException exc)
     {
         StandartJobs.MessageBox("Operation cannot be completed.\nReason: " + exc.Message, "Outlook Plugin",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     Trace.WriteLine("<<< Executing OutlookAction");
 }
Example #7
0
 protected virtual void ExecuteAction(IResourceList selectedResources)
 {
     try
     {
         foreach (IResource resource in selectedResources)
         {
             PairIDs pairIDs = PairIDs.Get(resource);
             //if ( pairIDs == null ) continue;
             ExecuteAction(resource, pairIDs);
         }
     }
     catch (Exception exception)
     {
         StandartJobs.MessageBox("Operation cannot be completed.\nReason: " + exception.Message, "Outlook Plugin",
                                 MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #8
0
        public void EnumerateMessageItems(FolderDescriptor folderDescriptor)
        {
            if (OutlookSession.WereProblemWithOpeningStorage(folderDescriptor.FolderIDs.StoreId) ||
                OutlookSession.WereProblemWithOpeningFolder(folderDescriptor.FolderIDs.EntryId))
            {
                return;
            }

            try
            {
                IEFolder mapiFolder =
                    OutlookSession.OpenFolder(folderDescriptor.FolderIDs.EntryId, folderDescriptor.FolderIDs.StoreId);
                if (mapiFolder == null)
                {
                    return;
                }
                using ( mapiFolder )
                {
                    string containerClass = mapiFolder.GetStringProp(MAPIConst.PR_CONTAINER_CLASS);
                    bool   taskFolder     = (FolderType.Task.Equals(containerClass));
                    if (taskFolder)
                    {
                        EnumerateTasks(folderDescriptor, mapiFolder);
                    }
                    else
                    {
                        EnumerateMail(folderDescriptor, mapiFolder);
                    }
                }
            }
            catch (COMException exception)
            {
                _tracer.TraceException(exception);
                if (exception.ErrorCode == MapiError.MAPI_E_NOT_ENOUGH_DISK)
                {
                    StandartJobs.MessageBox("Outlook reports that there is no enough disk space.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                OutlookSession.ProblemWithOpeningFolder(folderDescriptor.FolderIDs.EntryId);
                return;
            }
        }
Example #9
0
        public void SendReceive()
        {
            try
            {
                if (!OutlookSession.IsOutlookRun)
                {
                    OutlookGUIInit.StartOutlook(ProcessWindowStyle.Minimized);
                    if (!IsMainWndReady())
                    {
                        return;
                    }
                    OutlookGUIInit.ActivateGUI(_mainWnd);
                }
                _explorer = OutlookGUIInit.IsOutlookExplorerReady(cTimeOut);
                if (_explorer == null)
                {
                    StandartJobs.MessageBox(cErrorCOMInitialize, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                ProcessDeliverNow( );
                ReleaseCOM();
            }
            catch (COMException exception)
            {
                _tracer.TraceException(exception);
            }
            catch (FileNotFoundException exception)
            {
                _tracer.TraceException(exception);
            }
            catch (InvalidComObjectException exception)
            {
                _tracer.TraceException(exception);
            }
            catch (InvalidCastException exception)
            {
                _tracer.TraceException(exception);
            }
        }
Example #10
0
 private static bool MoveMessage(string storeID, string entryID, string folderID, PairIDs delFolderIds)
 {
     if (folderID == null)
     {
         return(false);
     }
     if (folderID != delFolderIds.EntryId)
     {
         IEFolder delFolder = OutlookSession.OpenFolder(delFolderIds.EntryId, delFolderIds.StoreId);
         if (delFolder == null)
         {
             return(false);
         }
         using ( delFolder )
         {
             IEFolder folder = OutlookSession.OpenFolder(folderID, storeID);
             if (folder == null)
             {
                 return(false);
             }
             using ( folder )
             {
                 try
                 {
                     folder.MoveMessage(entryID, delFolder);
                     return(true);
                 }
                 catch (COMException exception)
                 {
                     _tracer.TraceException(exception);
                     StandartJobs.MessageBox("Cannot complete deleting mail. Reason: " + exception.Message, "Error",
                                             MessageBoxButtons.OK, MessageBoxIcon.Error);
                     return(false);
                 }
             }
         }
     }
     return(false);
 }
Example #11
0
        public void SaveAs(string fileName)
        {
            FileStream fs = null;

            try
            {
                bool           setRO = false;
                FileAttributes attr  = FileAttributes.Normal;
                if (File.Exists(fileName))
                {
                    attr = File.GetAttributes(fileName);
                    if ((attr & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                    {
                        File.SetAttributes(fileName, attr & ~FileAttributes.ReadOnly);
                        setRO = true;
                    }
                }
                fs = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
                Stream.WriteTo(fs);
                if (setRO)
                {
                    File.SetAttributes(fileName, attr | FileAttributes.ReadOnly);
                }
            }
            catch (Exception exception)
            {
                StandartJobs.MessageBox(exception.Message, "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Example #12
0
        protected void ExecuteActionImpl(IResourceList selectedResources)
        {
            Tracer._Trace("Execute action: MoveFolderToFolderAction");
            if (_selectedFolder == null || _targetFolder == null)
            {
                return;
            }

            IEFolder destFolder =
                OutlookSession.OpenFolder(_selectedFolder.EntryId, _selectedFolder.StoreId);

            if (destFolder == null)
            {
                return;
            }

            using ( destFolder )
            {
                for (int i = 0; i < selectedResources.Count; i++)
                {
                    PairIDs folderIDs = PairIDs.Get(selectedResources[i]);
                    if (folderIDs == null)
                    {
                        continue;
                    }
                    IResource parentFolder    = Folder.GetParent(selectedResources[i]);
                    PairIDs   parentFolderIDs = PairIDs.Get(parentFolder);
                    if (parentFolderIDs == null)
                    {
                        continue;
                    }

                    IEFolder ieFolder =
                        OutlookSession.OpenFolder(parentFolderIDs.EntryId, parentFolderIDs.StoreId);
                    if (ieFolder == null)
                    {
                        continue;
                    }
                    using ( ieFolder )
                    {
                        Tracer._Trace("Move folder: " + folderIDs.EntryId.GetHashCode() + "/" + folderIDs.EntryId);
                        try
                        {
                            ieFolder.MoveFolder(folderIDs.EntryId, destFolder);
                        }
                        catch (COMException exception)
                        {
                            Tracer._TraceException(exception);
                            if (exception.ErrorCode == (unchecked ((int)0x8004010F)))
                            {
                                StandartJobs.MessageBox("Folder is not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else if (exception.ErrorCode == (unchecked ((int)0x80040604)))
                            {
                                StandartJobs.MessageBox("Collision. Probably target folder has subfolder with the same name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else if (exception.ErrorCode == (unchecked ((int)0x80040119)) || exception.ErrorCode == (unchecked ((int)0x8004dff2)))
                            {
                                StandartJobs.MessageBox("Unspecified error. Can't move or copt folder.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else
                            {
                                StandartJobs.MessageBox(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                }
            }
        }