예제 #1
0
        private void ImportYahooContact(IMirandaContact contact, IMirandaContactSettings settings,
                                        string group, bool myself)
        {
            string yahooId  = (string)settings.Settings ["yahoo_id"];
            string nickName = (string)settings.Settings ["Nick"];

            if (yahooId == null)
            {
                return;
            }

            ImportContactGeneric(contact, group, myself, "YAHOO", ResourceTypes.MirandaYahooAccount,
                                 new[] { Props.YahooId, Props.NickName }, new object[] { yahooId, nickName });
        }
예제 #2
0
        private void ImportAIMContact(IMirandaContact contact, IMirandaContactSettings settings,
                                      string group, bool myself)
        {
            string screenName = (string)settings.Settings ["SN"];
            string nickName   = (string)settings.Settings ["Nick"];

            if (screenName == null)
            {
                return;
            }

            ImportContactGeneric(contact, group, myself, "AIM", ResourceTypes.MirandaAIMAccount,
                                 new[] { Props.ScreenName, Props.NickName }, new object[] { screenName, nickName });
        }
예제 #3
0
        private void ImportJabberContact(IMirandaContact contact, IMirandaContactSettings settings,
                                         string group, bool myself)
        {
            string jabberID = (string)settings.Settings ["jid"];

            if (jabberID == null)
            {
                jabberID = (string)settings.Settings ["LoginName"] + "@" +
                           (string)settings.Settings ["LoginServer"];
            }
            string nickName = (string)settings.Settings ["Nick"];

            ImportContactGeneric(contact, group, myself, "JABBER", ResourceTypes.MirandaJabberAccount,
                                 new[] { Props.JabberId, Props.NickName }, new object[] { jabberID, nickName });
        }
예제 #4
0
        private void ImportContactGeneric(IMirandaContact contact, string group, bool myself,
                                          string moduleName, string accountResType, int[] propIds, object[] propValues)
        {
            IResource imAccount = Core.ResourceStore.FindUniqueResource(accountResType,
                                                                        propIds [0], propValues [0]);

            if (imAccount == null)
            {
                imAccount = Core.ResourceStore.BeginNewResource(accountResType);
                for (int i = 0; i < propIds.Length; i++)
                {
                    imAccount.SetProp(propIds [i], propValues [i]);
                }
                imAccount.EndUpdate();
            }

            if (myself)
            {
                _selfAccounts [moduleName] = imAccount;
            }
            else
            {
                IResource contactRes = imAccount.GetLinkProp(Props.MirandaAcct);
                if (contactRes == null)
                {
                    string contactName = imAccount.GetPropText(Props.NickName);
                    if (contactName.Length == 0)
                    {
                        contactName = imAccount.DisplayName;
                    }
                    IContact contactBO = Core.ContactManager.FindOrCreateContact(null, contactName);
                    contactRes = contactBO.Resource;
                    contactRes.AddLink(Props.MirandaAcct, imAccount);
                }
                AssignCategory(contactRes, group);
                ImportContactEvents(contact, imAccount, moduleName);
            }
        }
예제 #5
0
        private void ImportContactEvents(IMirandaContact contact, IResource accountRes, string moduleName)
        {
            if (contact == null)
            {
                throw new ArgumentNullException("contact");
            }
            if (accountRes == null)
            {
                throw new ArgumentNullException("accountRes");
            }

            TraceImport("Importing events for " + moduleName);
            DateTime firstImportedTime = accountRes.GetDateProp(Props.FirstMirandaImport);
            DateTime lastImportedTime  = accountRes.GetDateProp(Props.LastMirandaImport);

            TraceImport("First imported time " + firstImportedTime);
            TraceImport("Last imported time " + lastImportedTime);
            DateTime lastMessageTime  = DateTime.MinValue;
            DateTime firstMessageTime = firstImportedTime;

            int eventsImported = 0, eventsSkippedIndexStart = 0, eventsSkippedImportedTime = 0;

            IResource selfAccount = (IResource)_selfAccounts [moduleName];

            if (selfAccount == null)
            {
                Trace.WriteLine("Could not find self account for module " + moduleName);
                return;
            }
            if (selfAccount.GetLinkProp(Props.MirandaAcct) == null)
            {
                throw new Exception("Myself account is not linked to a contact");
            }
            if (accountRes.GetLinkProp(Props.MirandaAcct) == null)
            {
                throw new Exception("Account to import is not linked to a contact");
            }

            foreach (IMirandaEvent mirandaEvent in contact.Events)
            {
                if (mirandaEvent.ModuleName == moduleName && mirandaEvent.EventType == 0)
                {
                    if (mirandaEvent.Timestamp.ToLocalTime() < _indexStartDate)
                    {
                        eventsSkippedIndexStart++;
                        continue;
                    }

                    if (mirandaEvent.Timestamp < firstImportedTime || mirandaEvent.Timestamp > lastImportedTime)
                    {
                        if (mirandaEvent.Timestamp > lastMessageTime)
                        {
                            lastMessageTime = mirandaEvent.Timestamp;
                        }
                        if (mirandaEvent.Timestamp < firstMessageTime)
                        {
                            firstMessageTime = mirandaEvent.Timestamp;
                        }

                        IResource fromAccount, toAccount;

                        if ((mirandaEvent.Flags & 2) != 0)    // DBEF_SENT
                        {
                            fromAccount = selfAccount;
                            toAccount   = accountRes;
                        }
                        else
                        {
                            fromAccount = accountRes;
                            toAccount   = selfAccount;
                        }

                        IResource conversation = _conversationManager.Update(
                            mirandaEvent.EventData,
                            mirandaEvent.Timestamp.ToLocalTime(),
                            fromAccount, toAccount);
                        if (conversation != null)
                        {
                            _updatedConversations.Add(conversation.Id);
                        }
                        eventsImported++;
                    }
                    else
                    {
                        eventsSkippedImportedTime++;
                    }
                }
            }
            TraceImport(String.Format("Imported {0} events, skipped because of index start date - {1}, skipped because already imported - {2}",
                                      eventsImported, eventsSkippedIndexStart, eventsSkippedImportedTime));
            if (lastMessageTime > lastImportedTime)
            {
                accountRes.SetProp(Props.LastMirandaImport, lastMessageTime);
            }

            if (_indexStartDate != DateTime.MinValue)
            {
                accountRes.SetProp(Props.FirstMirandaImport, _indexStartDate);
            }
            else if (firstMessageTime < firstImportedTime)
            {
                accountRes.SetProp(Props.FirstMirandaImport, firstMessageTime);
            }
        }
예제 #6
0
        private void ImportICQContact(IMirandaContact contact, IMirandaContactSettings settings,
                                      string group, bool myself)
        {
            if (!settings.Settings.Contains("UIN"))
            {
                return;
            }

            int    UIN       = (int)settings.Settings ["UIN"];
            string firstName = (string)settings.Settings ["FirstName"];
            string lastName  = (string)settings.Settings ["LastName"];
            string email     = (string)settings.Settings ["e-mail"];
            string nick      = (string)settings.Settings ["Nick"];

            if (firstName == null)
            {
                firstName = "";
            }
            if (lastName == null)
            {
                lastName = "";
            }

            IResource contactRes;
            IResource icqAccount = Core.ResourceStore.FindUniqueResource(ResourceTypes.MirandaICQAccount,
                                                                         Props.UIN, UIN);

            if (icqAccount == null || !icqAccount.HasProp(Props.MirandaAcct))
            {
                if (icqAccount == null)
                {
                    icqAccount = Core.ResourceStore.BeginNewResource(ResourceTypes.MirandaICQAccount);
                    icqAccount.SetProp(Props.UIN, UIN);
                    icqAccount.SetProp(Props.NickName, nick);
                    icqAccount.EndUpdate();
                }

                if (firstName == "" && lastName == "")
                {
                    string contactName;
                    if (!string.IsNullOrEmpty(nick))
                    {
                        contactName = nick;
                    }
                    else
                    {
                        contactName = UIN.ToString();
                    }

                    IContact ct = Core.ContactManager.FindOrCreateContact(email, contactName);
                    contactRes = ct.Resource;
                }
                else
                {
                    IContact ct = Core.ContactManager.FindOrCreateContact(email, firstName, lastName);
                    contactRes = ct.Resource;
                }

                icqAccount.AddLink(Props.MirandaAcct, contactRes);
            }
            else
            {
                contactRes = icqAccount.GetLinkProp(Props.MirandaAcct);
            }

            AssignCategory(contactRes, group);
            if (_mirandaAB != null)
            {
                _mirandaAB.AddContact(contactRes);
            }

            else if (!contactRes.HasLink(Props.MirandaAcct, icqAccount))
            {
                contactRes.AddLink(Props.MirandaAcct, icqAccount);
            }

            if (myself)
            {
                _selfContact          = contactRes;
                _selfAccounts ["ICQ"] = icqAccount;
            }
            else
            {
                ImportContactEvents(contact, icqAccount, "ICQ");
            }
        }
예제 #7
0
        private void ImportContact(IMirandaContact contact, bool myself)
        {
            if (contact.LastEventOffset == _lastEventOffsets [contact.Offset])
            {
                return;
            }

            // guard for job reentering (we may have restarted the import job with a new database - OM-11022)
            if (contact.DatabaseClosed)
            {
                return;
            }

            try
            {
                _lastEventOffsets [contact.Offset] = contact.LastEventOffset;

                IMirandaContactSettings icqSettings    = null;
                IMirandaContactSettings aimSettings    = null;
                IMirandaContactSettings jabberSettings = null;
                IMirandaContactSettings yahooSettings  = null;
                string group = null;

                TraceImport("Importing contact at " + contact.Offset);
                foreach (IMirandaContactSettings settings in contact.ContactSettings)
                {
                    TraceImport("Found settings for " + settings.ModuleName);
                    if (String.Compare(settings.ModuleName, "ICQ", true) == 0)
                    {
                        icqSettings = settings;
                    }
                    else if (String.Compare(settings.ModuleName, "AIM", true) == 0)
                    {
                        aimSettings = settings;
                    }
                    else if (String.Compare(settings.ModuleName, "JABBER", true) == 0)
                    {
                        jabberSettings = settings;
                    }
                    else if (String.Compare(settings.ModuleName, "YAHOO", true) == 0)
                    {
                        yahooSettings = settings;
                    }
                    else if (String.Compare(settings.ModuleName, "CList", true) == 0)
                    {
                        group = (string)settings.Settings ["Group"];
                    }
                }
                if (icqSettings != null)
                {
                    ImportICQContact(contact, icqSettings, group, myself);
                }

                if (aimSettings != null)
                {
                    ImportAIMContact(contact, aimSettings, group, myself);
                }

                if (jabberSettings != null)
                {
                    ImportJabberContact(contact, jabberSettings, group, myself);
                }

                if (yahooSettings != null)
                {
                    ImportYahooContact(contact, yahooSettings, group, myself);
                }
            }
            catch (MirandaDatabaseCorruptedException ex)
            {
                CheckReportDBError("Database " + _dbPath + " is corrupted: " + ex.Message);
            }
        }