Esempio n. 1
0
        private void btnImport_Click(object sender, RibbonControlEventArgs e)
        {
            lblConverted.Label = "";
            lblNew.Label       = "";
            lblTotal.Label     = "";
            if (mapiMimeClass != null && mapiMimeClass.LstMapi != null)
            {
                if (mapiMimeClass.LstMapi.Count >= 500)
                {
                }
            }

            lstOutlookDirs = new List <string>();
            EnumerateFoldersInDefaultStore();
            if (lstOutlookDirs.Count >= 1)
            {
                FolderDecision fd = new FolderDecision(lstOutlookDirs, false);
                DialogResult   dr = fd.ShowDialog();
                if (!string.IsNullOrEmpty(fd.SelectedFolder))
                {
                    targetDirOutlook = fd.SelectedFolder;
                    if (mapiMimeClass != null && mapiMimeClass.LstMapi != null && mapiMimeClass.LstMapi.Count >= 1)
                    {
                        btnImport.Enabled    = false;
                        btnDirectory.Enabled = false;
                        btnHelp.Enabled      = false;
                        btnClean.Enabled     = false;
                        btnConfig.Enabled    = false;

                        BackgroundWorker bwAdd = new BackgroundWorker();
                        bwAdd.DoWork             += bwAdd_DoWork;
                        bwAdd.RunWorkerCompleted += bwAdd_RunWorkerCompleted;
                        bwAdd.RunWorkerAsync();
                    }
                    else
                    {
                        lblTotal.Label = rm.GetString("lblTotalNoFilesInsideDirRes");
                    }
                }
            }
        }
Esempio n. 2
0
        public bool SetConversation(ref string kom)
        {
            try
            {
                string     folderToSync = string.Empty;
                string     days         = string.Empty;
                FolderView view         = new FolderView(100);
                view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
                view.PropertySet.Add(FolderSchema.DisplayName);
                view.Traversal = FolderTraversal.Deep;
                if (service != null)
                {
                    List <string> lstDirsToChoose  = new List <string>();
                    List <string> lstDirsToDisplay = new List <string>();
                    //find specific folder

                    lstDirsToChoose.Add(WellKnownFolderName.Inbox.ToString());
                    lstDirsToChoose.Add(WellKnownFolderName.SentItems.ToString());
                    lstDirsToDisplay.Add(WellKnownFolderName.Inbox.ToString());
                    lstDirsToDisplay.Add(WellKnownFolderName.SentItems.ToString());

                    FolderDecision fd = new FolderDecision(lstDirsToDisplay, true);
                    fd.SelectedFolder = lstDirsToChoose.FirstOrDefault();
                    fd.ShowDialog();

                    if (!Directory.Exists(mailDir + "\\" + fd.SelectedFolder.Replace(" ", "")))
                    {
                        Directory.CreateDirectory(mailDir + "\\" + fd.SelectedFolder.Replace(" ", ""));
                    }
                    mailDir      = mailDir + "\\" + fd.SelectedFolder.Replace(" ", "");
                    folderToSync = lstDirsToChoose.Where(q => q == fd.SelectedFolder).FirstOrDefault();
                    days         = fd.SelectedTime;

                    SearchFilter sfs = new SearchFilter.IsGreaterThan(ItemSchema.DateTimeReceived, DateTime.Now.AddDays(-int.Parse(days)));

                    int      offset   = 0;
                    int      pageSize = 50;
                    bool     more     = true;
                    ItemView viewItem = new ItemView(pageSize, offset, OffsetBasePoint.Beginning);

                    FindItemsResults <Item> findResults;
                    List <EmailMessage>     emails = new List <EmailMessage>();

                    while (more)
                    {
                        WellKnownFolderName folderName = WellKnownFolderName.Inbox;
                        if (folderToSync == WellKnownFolderName.Inbox.ToString())
                        {
                            folderName = WellKnownFolderName.Inbox;
                        }
                        if (folderToSync == WellKnownFolderName.SentItems.ToString())
                        {
                            folderName = WellKnownFolderName.SentItems;
                        }

                        findResults = service.FindItems(folderName, sfs, viewItem);
                        foreach (var item in findResults.Items)
                        {
                            emails.Add((EmailMessage)item);
                        }

                        more = findResults.MoreAvailable;
                        if (more)
                        {
                            viewItem.Offset += pageSize;
                        }
                    }
                    PropertySet properties = (BasePropertySet.FirstClassProperties); //A PropertySet with the explicit properties you want goes here
                    service.LoadPropertiesForItems(emails, properties);
                    int index = 1;
                    foreach (EmailMessage em in emails)
                    {
                        em.Load(new PropertySet(ItemSchema.MimeContent));
                        MimeContent mc    = em.MimeContent;
                        string      nazwa = BitConverter.ToString(MD5.Create().ComputeHash(ASCIIEncoding.ASCII.GetBytes(em.Id.UniqueId)));
                        if (!File.Exists(mailDir + "\\" + nazwa + ".eml"))
                        {
                            File.WriteAllBytes(mailDir + "\\" + nazwa + ".eml", em.MimeContent.Content);
                            OnNewFilesNumberEvent(string.Format("{0} {1}", index, _rm.GetString("strNewEmailsInsideOutlookDirRes")));
                            index++;
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                kom = _rm.GetString("lblTotalGenericErrorRes") + " " + ex.Message;
                return(false);
            }
        }
Esempio n. 3
0
        public bool SetConversation(string sessionKey, string syncKey, ref string kom)
        {
            try
            {
                string            folderToSync    = string.Empty;
                string            days            = string.Empty;
                uint              policyKey       = uint.Parse(sessionKey);
                StringBuilder     xmlBuilder      = null;
                ASCommandRequest  commandRequest  = null;
                ASCommandResponse commandResponse = null;
                string            postfixFolder   = string.Empty;
                if (syncKey == "0")
                {
                    xmlBuilder = new StringBuilder();
                    if (Directory.Exists(mailDir))
                    {
                        xmlBuilder.Append(SetFolderSyncObjectAsXml("0"));
                    }

                    commandRequest = CreateCommandRequest("FolderSync", cred, devID, devType, protVer, server, username, xmlBuilder.ToString(), policyKey);

                    // Send the request
                    commandResponse = commandRequest.GetResponse();

                    Console.WriteLine("XML Response: {0}", commandResponse.XmlString);
                    EAS.generated.FolderResponseNamespace.FolderSync fsFromEAS = GetFolderSyncObjectFromXML(commandResponse.XmlString);

                    if (fsFromEAS != null && fsFromEAS.Status == "1" && fsFromEAS.Changes != null && fsFromEAS.Changes.Add != null)
                    {
                        List <List <string> > lstDirsToChoose  = new List <List <string> >();
                        List <string>         lstDirsToDisplay = new List <string>();
                        foreach (EAS.generated.FolderResponseNamespace.FolderSyncChangesAdd fsca in fsFromEAS.Changes.Add)
                        {
                            if (fsca.Type == "5" || fsca.Type == "2")
                            {
                                lstDirsToChoose.Add(new List <string> {
                                    fsca.ServerId, fsca.DisplayName
                                });
                                lstDirsToDisplay.Add(fsca.DisplayName);
                            }
                        }
                        FolderDecision fd = new FolderDecision(lstDirsToDisplay, true);
                        fd.SelectedFolder = lstDirsToChoose.Where(q => q[0] == "4").FirstOrDefault()[1];
                        fd.ShowDialog();

                        if (!Directory.Exists(mailDir + "\\" + fd.SelectedFolder.Replace(" ", "")))
                        {
                            Directory.CreateDirectory(mailDir + "\\" + fd.SelectedFolder.Replace(" ", ""));
                        }
                        mailDir      = mailDir + "\\" + fd.SelectedFolder.Replace(" ", "");
                        folderToSync = lstDirsToChoose.Where(q => q[1] == fd.SelectedFolder).FirstOrDefault()[0];
                        days         = fd.SelectedTime;
                    }

                    //sync 1

                    xmlBuilder = new StringBuilder();

                    xmlBuilder.Append(SetSyncObjectAsXml(syncKey, folderToSync, days));

                    XmlDocument xDoc = new XmlDocument();
                    xDoc.PreserveWhitespace = true;
                    xDoc.LoadXml(xmlBuilder.ToString());

                    commandRequest.XmlString = xDoc.InnerXml;

                    // Send the request
                    commandRequest  = CreateCommandRequest("Sync", cred, devID, devType, protVer, server, username, xmlBuilder.ToString(), policyKey);
                    commandResponse = commandRequest.GetResponse();

                    EAS.generated.SyncResponseNamespace.Sync syncResponse = GetSyncObjectFromXML(commandResponse.XmlString);
                    if (syncResponse != null)
                    {
                        if (syncResponse.Item is EAS.generated.SyncResponseNamespace.SyncCollections)
                        {
                            EAS.generated.SyncResponseNamespace.SyncCollections sc = (EAS.generated.SyncResponseNamespace.SyncCollections)syncResponse.Item;

                            if (sc.Collection != null)
                            {
                                //WYCHWYC INBOX
                                foreach (EAS.generated.SyncResponseNamespace.SyncCollectionsCollection scc in sc.Collection)
                                {
                                    List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7> lst = new List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7>(scc.ItemsElementName);
                                    int index = lst.FindIndex(q => q == EAS.generated.SyncResponseNamespace.ItemsChoiceType7.CollectionId);
                                    if (index > 0)
                                    {
                                        if (scc.Items[index].ToString() == folderToSync)
                                        {
                                            List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7> lstSync = new List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7>(scc.ItemsElementName);
                                            int indexSync = lst.FindIndex(q => q == EAS.generated.SyncResponseNamespace.ItemsChoiceType7.SyncKey);

                                            syncKey = scc.Items[indexSync].ToString();
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                List <string> lstEmailsToFetch = new List <string>();
                bool          continuingLoop   = true;
                do
                {
                    //sync2
                    xmlBuilder = new StringBuilder();
                    xmlBuilder.Append(SetSyncObjectAsXml(syncKey, folderToSync, days));

                    // Send the request
                    commandRequest           = CreateCommandRequest("Sync", cred, devID, devType, protVer, server, username, xmlBuilder.ToString(), policyKey);
                    commandRequest.XmlString = xmlBuilder.ToString();
                    commandResponse          = commandRequest.GetResponse();

                    EAS.generated.SyncResponseNamespace.Sync syncResponse2 = GetSyncObjectFromXML(commandResponse.XmlString);

                    if (syncResponse2 != null)
                    {
                        if (syncResponse2.Item is EAS.generated.SyncResponseNamespace.SyncCollections)
                        {
                            EAS.generated.SyncResponseNamespace.SyncCollections sc = (EAS.generated.SyncResponseNamespace.SyncCollections)syncResponse2.Item;

                            if (sc.Collection != null)
                            {
                                EAS.generated.SyncResponseNamespace.SyncCollectionsCollection[] scc = sc.Collection;
                                foreach (EAS.generated.SyncResponseNamespace.SyncCollectionsCollection sccItem in scc)
                                {
                                    List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7> lst = new List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7>(sccItem.ItemsElementName);
                                    int index = lst.FindIndex(q => q == EAS.generated.SyncResponseNamespace.ItemsChoiceType7.CollectionId);
                                    if (index > 0)
                                    {
                                        if (sccItem.Items[index].ToString() == folderToSync)
                                        {
                                            EAS.generated.SyncResponseNamespace.SyncCollectionsCollectionCommands sccc    = null;
                                            List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7>           lstSync = new List <EAS.generated.SyncResponseNamespace.ItemsChoiceType7>(sccItem.ItemsElementName);
                                            int indexCommand = lst.FindIndex(q => q == EAS.generated.SyncResponseNamespace.ItemsChoiceType7.Commands);

                                            if (indexCommand > -1)
                                            {
                                                if (sccItem.Items[indexCommand] is EAS.generated.SyncResponseNamespace.SyncCollectionsCollectionCommands)
                                                {
                                                    sccc = (EAS.generated.SyncResponseNamespace.SyncCollectionsCollectionCommands)sccItem.Items[indexCommand];
                                                    foreach (object o in sccc.Items)
                                                    {
                                                        if (o is EAS.generated.SyncResponseNamespace.SyncCollectionsCollectionCommandsAdd)
                                                        {
                                                            EAS.generated.SyncResponseNamespace.SyncCollectionsCollectionCommandsAdd sccca = (EAS.generated.SyncResponseNamespace.SyncCollectionsCollectionCommandsAdd)o;
                                                            lstEmailsToFetch.Add(sccca.ServerId);
                                                            OnTotalNumberOfFilesEvent(string.Format("{0} {1}", lstEmailsToFetch.Count.ToString(), _rm.GetString("strEmailsToSync")));
                                                        }
                                                    }
                                                }
                                            }

                                            int synckeyIdx = lst.FindIndex(q => q == EAS.generated.SyncResponseNamespace.ItemsChoiceType7.SyncKey);

                                            if (synckeyIdx > -1)
                                            {
                                                syncKey = sccItem.Items[synckeyIdx].ToString();
                                                syncKey = (int.Parse(syncKey)).ToString();
                                            }

                                            int moreAvailableIdx = lst.FindIndex(q => q == EAS.generated.SyncResponseNamespace.ItemsChoiceType7.MoreAvailable);
                                            if (moreAvailableIdx > -1)
                                            {
                                                continuingLoop = true;
                                            }
                                            else
                                            {
                                                continuingLoop = false;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(_rm.GetString("errSerialization"));
                    }
                }while (continuingLoop);

                WriteEmailsToDirectory(lstEmailsToFetch, folderToSync, policyKey);

                return(true);
            }
            catch (Exception ex)
            {
                kom = _rm.GetString("lblTotalGenericErrorRes") + " " + ex.Message;
                return(false);
            }
        }