Exemplo n.º 1
0
        /// <summary>
        /// Add the EmailSource.
        /// </summary>
        private static void AddEmailSource(PXGraph graph, int?sourceEmailID, RecipientList recipients)
        {
            NotificationRecipient recipient = null;

            EMailAccount emailAccountRow = PXSelect <EMailAccount,
                                                     Where <
                                                         EMailAccount.emailAccountID, Equal <Required <EMailAccount.emailAccountID> > > >
                                           .Select(graph, sourceEmailID);

            if (emailAccountRow != null && emailAccountRow.Address != null)
            {
                recipient = new NotificationRecipient()
                {
                    Active = true,
                    Email  = emailAccountRow.Address,
                    Hidden = false,
                    Format = "H"
                };

                if (recipient != null)
                {
                    recipients.Add(recipient);
                }
            }
        }
Exemplo n.º 2
0
        private void SendCopyMessageToInside(PXGraph graph, EMailAccount account, EPActivity message, IEnumerable <Mailbox> email)
        {
            var cache = graph.Caches[message.GetType()];
            var copy  = (EPActivity)cache.CreateCopy(message);

            copy.TaskID       = null;
            copy.IsIncome     = false;
            copy.ParentTaskID = message.TaskID;
            copy.MailTo       = ConcatAddresses(email);       //TODO: need add address description
            copy.MailCc       = null;
            copy.MailBcc      = null;
            copy.MPStatus     = MailStatusListAttribute.PreProcess;
            copy.ClassID      = CRActivityClass.EmailRouting;
            new AddInfoEmailProcessor().Process(new EmailProcessEventArgs(graph, account, copy));
            copy.RefNoteID       = null;
            copy.ParentRefNoteID = null;
            var imcUid = Guid.NewGuid();

            copy.ImcUID    = imcUid;
            copy.MessageId = GetType().Name + "_" + imcUid.ToString().Replace("-", string.Empty);
            copy.Owner     = message.Owner;
            copy.IsPrivate = message.IsPrivate;
            cache.Insert(copy);
            var noteFiles = PXNoteAttribute.GetFileNotes(cache, message);

            if (noteFiles != null)
            {
                PXNoteAttribute.SetFileNotes(cache, copy, noteFiles);
            }
        }
Exemplo n.º 3
0
        protected virtual void Contact_Email_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
        {
            Contact contact = (Contact)e.Row;

            foreach (EMailSyncAccount syncAccount in SyncAccount.Select(contact.ContactID)
                     .RowCast <EMailSyncAccount>()
                     .Select(account => (EMailSyncAccount)SyncAccount.Cache.CreateCopy(account)))
            {
                syncAccount.Address = contact.EMail;

                syncAccount.ContactsExportDate = null;
                syncAccount.ContactsImportDate = null;
                syncAccount.EmailsExportDate   = null;
                syncAccount.EmailsImportDate   = null;
                syncAccount.TasksExportDate    = null;
                syncAccount.TasksImportDate    = null;
                syncAccount.EventsExportDate   = null;
                syncAccount.EventsImportDate   = null;

                EMailAccount mailAccount = EMailAccounts.Select(syncAccount.EmailAccountID);
                mailAccount.Address = syncAccount.Address;

                EMailAccounts.Update(mailAccount);
                SyncAccount.Update(syncAccount);
            }
        }
Exemplo n.º 4
0
        private void convertToCaseProcess()
        {
            var Receive        = new CommonMailReceiveProvider();
            var MailDictionary = GetMailByAccount();

            foreach (var accountmessages in MailDictionary)
            {
                EMailAccount emailaccount = PXSelect <EMailAccount,
                                                      Where <EMailAccount.emailAccountID, Equal <Required <EMailAccount.emailAccountID> > > > .Select(this, accountmessages.Key)[0];

                emailaccount.CreateCase         = true;
                emailaccount.IncomingProcessing = true;

                emailaccount.ConfirmReceipt    = false;
                emailaccount.CreateActivity    = false;
                emailaccount.CreateLead        = false;
                emailaccount.ProcessUnassigned = false;
                emailaccount.DeleteUnProcessed = false;
                foreach (var message in MailDictionary[accountmessages.Key])
                {
                    if (message.IsIncome == true)
                    {
                        message.RefNoteID       = null;
                        message.ParentRefNoteID = null;
                        Receive.ProcessMessage(emailaccount, message);
                    }
                }
            }
        }
        protected override bool Process(Package package)
        {
            CRSMEmail    activity = package.Message;
            EMailAccount account  = package.Account;
            PXGraph      graph    = package.Graph;

            if (account.EmailAccountType != EmailAccountTypesAttribute.Exchange)
            {
                return(false);
            }


            foreach (EPEmployee employee in PXSelectJoin <EPEmployee,
                                                          InnerJoin <EMailSyncAccount, On <EPEmployee.bAccountID, Equal <EMailSyncAccount.employeeID> > >,
                                                          Where <EMailSyncAccount.emailAccountID, Equal <Required <EMailSyncAccount.emailAccountID> > > > .Select(graph, account.EmailAccountID))
            {
                if (employee.UserID != null)
                {
                    activity.OwnerID = employee.UserID;
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 6
0
            private void ReadAccount(int?accountID)
            {
                int?         smtpAccount = accountID;
                EMailAccount account     = null;

                if (smtpAccount != null)
                {
                    account = ReadAccountSettings(smtpAccount);
                }
                if (account == null)
                {
                    account = ReadDefaultAccountSettings();
                }
                if (account == null)
                {
                    throw new PXException(ErrorMessages.EmailNotConfigured);
                }
                if (string.IsNullOrEmpty(account.Address.With(_ => _.Trim())))
                {
                    throw new PXException(Messages.EmptyEmailAccountAddress);
                }

                var mailer = MailAccountManager.GetSender(account);

                if (mailer == null)
                {
                    throw new PXException(ErrorMessages.EmailNotConfigured);
                }

                _account = account;
                _mailer  = mailer;
            }
Exemplo n.º 7
0
        protected override bool Process(Package package)
        {
            CRSMEmail    activity = package.Message;
            EMailAccount account  = package.Account;

            if (activity.IsIncome != true ||
                activity.OwnerID != null ||
                activity.WorkgroupID != null ||
                activity.ClassID == CRActivityClass.EmailRouting)
            {
                return(false);
            }

            bool assigned = false;

            if (account.DefaultEmailAssignmentMapID != null)
            {
                var processor = PXGraph.CreateInstance <EPAssignmentProcessor <CRSMEmail> >();
                assigned = processor.Assign(activity, account.DefaultEmailAssignmentMapID);
            }
            if (!assigned)
            {
                activity.OwnerID     = account.DefaultOwnerID;
                activity.WorkgroupID = account.DefaultWorkgroupID;
            }

            return(true);
        }
Exemplo n.º 8
0
            private string GenerateSubject(SMEmail message)
            {
                var subject = message.Subject;

                if (message.Ticket == null)
                {
                    message.Ticket = message.ID;
                }
                if (message.Ticket != null)
                {
                    EMailAccount account =
                        PXSelect <EMailAccount, Where <EMailAccount.emailAccountID, Equal <Required <EMailAccount.emailAccountID> > > > .Select(_graph,
                                                                                                                                                message.MailAccountID);

                    if (account != null && account.IncomingProcessing == true)
                    {
                        var ticket = EncodeTicket(message.ID.GetValueOrDefault());
                        subject = message.Subject.StartsWith("FW: ") || message.Subject.StartsWith("RE: ")
                                        ? message.Subject.Substring(0, 4) + message.Subject.Substring(4)
                                        : message.Subject;
                        subject += " " + ticket;
                    }
                }
                return(subject);
            }
Exemplo n.º 9
0
        protected override bool Process(Package package)
        {
            EMailAccount account = package.Account;
            CRSMEmail    message = package.Message;
            PXGraph      graph   = package.Graph;

            if (message.Body == null)
            {
                return(true);
            }

            if (message.NoteID == null)
            {
                return(false);
            }

            Guid noteID    = message.NoteID.Value;
            var  extractor = new PX.Data.ImageExtractor();
            var  body      = message.Body;

            if (extractor.ExtractEmbedded(body, img => AddExtractedImage(graph, noteID, img),
                                          out var newBody, out var _))
            {
                message.Body = newBody;
            }

            return(true);
        }
Exemplo n.º 10
0
        private void OnAddNewEmailAccount()
        {
            EMailAccount newAccount = new EMailAccount();

            newAccount.EmailAddress = "bitte gültige Adresse eingeben";
            newAccount.InvestorId   = Investor.Id;
            EMailAccounts.Add(newAccount);
        }
Exemplo n.º 11
0
        protected void SendCopyMessageToInside(PXGraph graph, EMailAccount account, CRSMEmail message, IEnumerable <MailAddress> addresses)
        {
            var cache = graph.Caches[message.GetType()];
            var copy  = (CRSMEmail)cache.CreateCopy(message);

            copy.NoteID       = null;
            copy.EmailNoteID  = null;
            copy.IsIncome     = false;
            copy.ParentNoteID = message.NoteID;
            MailAddress address = null;

            copy.MailFrom = EmailParser.TryParse(message.MailFrom, out address)
                                ? new MailAddress(account.Address, address.DisplayName).ToString()
                                : account.Address;
            copy.MailTo    = PXDBEmailAttribute.ToString(addresses);          //TODO: need add address description
            copy.MailCc    = null;
            copy.MailBcc   = null;
            copy.MailReply = copy.MailFrom;
            copy.MPStatus  = MailStatusListAttribute.PreProcess;
            copy.ClassID   = CRActivityClass.EmailRouting;
            new AddInfoEmailProcessor().Process(new EmailProcessEventArgs(graph, account, copy));
            copy.RefNoteID  = null;
            copy.BAccountID = null;
            copy.ContactID  = null;
            copy.Pop3UID    = null;
            copy.ImapUID    = null;
            var imcUid = Guid.NewGuid();

            copy.ImcUID      = imcUid;
            copy.MessageId   = this.GetType().Name + "_" + imcUid.ToString().Replace("-", string.Empty);
            copy.OwnerID     = null;
            copy.WorkgroupID = null;

            copy = (CRSMEmail)cache.CreateCopy(cache.Insert(copy));

            //Update owner and reset owner if employee not found
            copy.OwnerID = message.OwnerID;
            try
            {
                cache.Update(copy);
            }
            catch (PXSetPropertyException)
            {
                copy.OwnerID = null;
                copy         = (CRSMEmail)cache.CreateCopy(cache.Update(copy));
            }

            copy.IsPrivate   = message.IsPrivate;
            copy.WorkgroupID = message.WorkgroupID;

            var noteFiles = PXNoteAttribute.GetFileNotes(cache, message);

            if (noteFiles != null)
            {
                PXNoteAttribute.SetFileNotes(cache, copy, noteFiles);
            }
        }
            private MailProcessor(PXGraph graph, EMailAccount account, Email email)
                : this(graph, account)
            {
                if (email == null)
                {
                    throw new ArgumentNullException("email");
                }

                _email = email;
            }
		public EmailProcessEventArgs(PXGraph graph, EMailAccount account, EPActivity message)
		{
			if (graph == null) throw new ArgumentNullException("graph");
			if (account == null) throw new ArgumentNullException("account");
			if (message == null) throw new ArgumentNullException("message");

			_graph = graph;
			_account = account;
			_message = message;
		}
Exemplo n.º 14
0
			private Package(PXGraph graph, EMailAccount account, EPActivity message)
			{
				if (graph == null) throw new ArgumentNullException("graph");
				if (account == null) throw new ArgumentNullException("account");
				if (message == null) throw new ArgumentNullException("message");

				_graph = graph;
				_account = account;
				_message = message;
			}
            private MailProcessor(PXGraph graph, EMailAccount account, SMEmail message)
                : this(graph, account)
            {
                if (message == null)
                {
                    throw new ArgumentNullException("message");
                }

                _message = message;
            }
            private MailProcessor(PXGraph graph, EMailAccount account, PX.Objects.CR.EPActivity message)
                : this(graph, account)
            {
                if (message == null)
                {
                    throw new ArgumentNullException("message");
                }

                _message = message;
            }
Exemplo n.º 17
0
        protected override bool Process(Package package)
        {
            PXGraph      graph   = package.Graph;
            EMailAccount account = package.Account;
            CRSMEmail    message = package.Message;

            if (account != null && (
                    (account.ForbidRouting ?? false) ||
                    !(account.RouteEmployeeEmails ?? false)
                    ))
            {
                return(false);
            }

            bool?isFromInternalUser = IsFromInternalUser(graph, message);
            var  recipients         = new MailAddressList();

            if (isFromInternalUser == true)
            {
                recipients.AddRange(GetExternalRecipient(graph, message));
            }
            else if (isFromInternalUser == false)
            {
                recipients.AddRange(GetInternalRecipient(graph, message));
            }
            else
            {
                return(false);                // for those users and employees which are disabled or RouteEmails switched off
            }
            RemoveAddress(recipients, message.MailFrom);
            RemoveAddress(recipients, message.MailTo);
            RemoveAddress(recipients, message.MailCc);
            RemoveAddress(recipients, message.MailBcc);

            if (recipients.Count == 0)
            {
                return(false);
            }

            if (isFromInternalUser == true)
            {
                SendCopyMessageToOutside(graph, package.Account, message, recipients);
                MarkAsRoutingEmail(graph, message);
                MarkAsRead(graph, message);
            }
            else
            {
                SendCopyMessageToInside(graph, package.Account, message, recipients);
            }

            graph.EnsureCachePersistence(message.GetType());

            return(true);
        }
        private void SendCopyMessage(PXGraph graph, EMailAccount account, CRSMEmail message, string email)
        {
            var cache = graph.Caches[message.GetType()];
            var copy  = (CRSMEmail)cache.CreateCopy(message);

            copy.NoteID       = null;
            copy.EmailNoteID  = null;
            copy.IsIncome     = false;
            copy.ParentNoteID = message.NoteID;
            copy.MailTo       = email;       //TODO: need add address description
            copy.MailCc       = null;
            copy.MailBcc      = null;
            copy.MPStatus     = MailStatusListAttribute.PreProcess;
            copy.ClassID      = CRActivityClass.EmailRouting;
            new AddInfoEmailProcessor().Process(new EmailProcessEventArgs(graph, account, copy));
            copy.RefNoteID  = null;
            copy.BAccountID = null;
            copy.ContactID  = null;
            copy.Pop3UID    = null;
            copy.ImapUID    = null;
            var imcUid = Guid.NewGuid();

            copy.ImcUID      = imcUid;
            copy.MessageId   = this.GetType().Name + "_" + imcUid.ToString().Replace("-", string.Empty);
            copy.OwnerID     = null;
            copy.WorkgroupID = null;

            copy = (CRSMEmail)cache.CreateCopy(cache.Insert(copy));

            //Update owner and reset owner if employee not found
            copy.OwnerID = message.OwnerID;
            try
            {
                cache.Update(copy);
            }
            catch (PXSetPropertyException)
            {
                copy.OwnerID = null;
                copy         = (CRSMEmail)cache.CreateCopy(cache.Update(copy));
            }

            copy.WorkgroupID = message.WorkgroupID;

            var noteFiles = PXNoteAttribute.GetFileNotes(cache, message);

            if (noteFiles != null)
            {
                PXNoteAttribute.SetFileNotes(cache, copy, noteFiles);
            }
            graph.EnsureCachePersistence(copy.GetType());
        }
Exemplo n.º 19
0
        private void SendCopyMessageToOutside(PXGraph graph, EMailAccount account, CRSMEmail message, IEnumerable <Mailbox> email)
        {
            var cache = graph.Caches[message.GetType()];
            var copy  = (CRSMEmail)cache.CreateCopy(message);

            copy.NoteID       = null;
            copy.EmailNoteID  = null;
            copy.IsIncome     = false;
            copy.ParentNoteID = message.NoteID;
            Mailbox mailFrom;

            copy.MailFrom = Mailbox.TryParse(message.MailFrom, out mailFrom)
                ? new Mailbox(mailFrom.DisplayName, account.Address).ToString()
                : account.Address;
            copy.MailTo   = ConcatAddresses(email); //TODO: need add address description
            copy.MailCc   = null;
            copy.MailBcc  = null;
            copy.MPStatus = MailStatusListAttribute.PreProcess;
            copy.ClassID  = CRActivityClass.Email;
            var imcUid = Guid.NewGuid();

            copy.ImcUID       = imcUid;
            copy.MessageId    = GetType().Name + "_" + imcUid.ToString().Replace("-", string.Empty);
            copy.IsPrivate    = message.IsPrivate;
            copy.OwnerID      = null;
            copy.ParentNoteID = null;

            copy = (CRSMEmail)cache.CreateCopy(cache.Insert(copy));

            //Update owner and reset owner if employee not found
            copy.OwnerID = message.OwnerID;
            try
            {
                copy = (CRSMEmail)cache.Update(copy);
            }
            catch (PXSetPropertyException)
            {
                copy.OwnerID = null;
                copy         = (CRSMEmail)cache.Update(copy);
            }

            copy.ParentNoteID = message.NoteID;

            var noteFiles = PXNoteAttribute.GetFileNotes(cache, message);

            if (noteFiles != null)
            {
                PXNoteAttribute.SetFileNotes(cache, copy, noteFiles);
            }
        }
Exemplo n.º 20
0
        private static Tuple <EMailSyncServer, EMailSyncPolicy, PXSyncMailbox> GetConfig(int emailAccountID)
        {
            PXGraph graph = new PXGraph();

            foreach (PXResult <EMailSyncAccount, EMailSyncServer, EMailAccount, EPEmployee, Contact> row in
                     PXSelectJoin <EMailSyncAccount,
                                   InnerJoin <EMailSyncServer, On <EMailSyncServer.accountID, Equal <EMailSyncAccount.serverID> >,
                                              InnerJoin <EMailAccount, On <EMailAccount.emailAccountID, Equal <EMailSyncAccount.emailAccountID> >,
                                                         LeftJoin <EPEmployee, On <EMailSyncAccount.employeeID, Equal <EPEmployee.bAccountID> >,
                                                                   LeftJoin <Contact, On <EPEmployee.defContactID, Equal <Contact.contactID>, And <EPEmployee.parentBAccountID, Equal <Contact.bAccountID> > > > > > >,
                                   Where <EMailSyncAccount.emailAccountID, Equal <Required <EMailSyncAccount.emailAccountID> > >,
                                   OrderBy <Asc <EMailSyncAccount.serverID, Asc <EMailSyncAccount.employeeID> > > > .SelectSingleBound(graph, null, emailAccountID))
            {
                EMailSyncServer  server       = row;
                EMailSyncAccount account      = row;
                Contact          contact      = row;
                EMailAccount     eMailAccount = row;

                if (server == null || account == null || String.IsNullOrEmpty(account.Address))
                {
                    throw new PXException(Messages.EmailExchangeAccountNotFound);
                }
                if (server.IsActive != true)
                {
                    throw new PXException(Messages.EmailExchangeAccountNotEnabled);
                }

                string address = (contact != null ? contact.EMail : null) ?? account.Address;

                PXSyncMailbox mailbox = new PXSyncMailbox(address, account.EmployeeID.Value, emailAccountID, new PXSyncMailboxPreset(null, null), new PXSyncMailboxPreset(null, null), eMailAccount.IncomingProcessing ?? false);

                string          policyName = account.PolicyName ?? server.DefaultPolicyName;
                EMailSyncPolicy policy     = PXSelect <EMailSyncPolicy, Where <EMailSyncPolicy.policyName, Equal <Required <EMailSyncPolicy.policyName> > > > .SelectSingleBound(graph, null, policyName);

                if (policy == null)
                {
                    throw new PXException(Messages.EmailExchangePolicyNotFound, account.Address);
                }

                if (String.IsNullOrEmpty(server.ServerType) || !_exchangers.ContainsKey(server.ServerType))
                {
                    throw new PXException(Messages.EmailExchangeProviderNotFound);
                }

                return(Tuple.Create(server, policy, mailbox));
            }

            throw new PXException(Messages.EmailExchangeAccountNotFound);
        }
Exemplo n.º 21
0
        private PXResult <CRSMEmail, EMailAccount, EPView> GetActivityResult(CRSMEmail a)
        {
            EMailAccount acc = PXSelectReadonly <EMailAccount,
                                                 Where <EMailAccount.emailAccountID, Equal <Required <CRSMEmail.mailAccountID> > > > .Select(this, a.MailAccountID);

            EPView v = PXSelectReadonly <EPView,
                                         Where <Required <CRSMEmail.noteID>, Equal <EPView.noteID>,
                                                And <Required <CRSMEmail.ownerID>, Equal <EPView.userID> > > > .Select(this, a.NoteID, a.OwnerID);

            return(new PXResult <CRSMEmail, EMailAccount, EPView>(a, acc ?? new EMailAccount {
                EmailAccountID = a.MailAccountID
            }, v ?? new EPView {
                NoteID = a.NoteID, UserID = a.OwnerID
            }));
        }
        protected override bool Process(Package package)
        {
            PXGraph      graph   = package.Graph;
            EMailAccount account = package.Account;
            CRSMEmail    message = package.Message;

            if (account != null && (account.ForbidRouting ?? false))
            {
                return(false);
            }

            var isFromInternalUser = IsFromInternalUser(graph, message);
            var recipients         = new MailAddressList();

            if (isFromInternalUser)
            {
                recipients.AddRange(GetExternalRecipient(graph, message));
            }
            else
            {
                recipients.AddRange(GetInternalRecipient(graph, message));
            }

            RemoveAddress(recipients, message.MailFrom);
            RemoveAddress(recipients, message.MailTo);
            RemoveAddress(recipients, message.MailCc);
            RemoveAddress(recipients, message.MailBcc);

            if (recipients.Count == 0)
            {
                return(false);
            }

            if (isFromInternalUser)
            {
                SendCopyMessageToOutside(graph, package.Account, message, recipients);
                MarkAsRoutingEmail(graph, message);
                MarkAsRead(graph, message);
            }
            else
            {
                SendCopyMessageToInside(graph, package.Account, message, recipients);
            }

            graph.EnsureCachePersistence(message.GetType());

            return(true);
        }
Exemplo n.º 23
0
        private void UpdateEMailAccountsForInvestor(Investor investor)
        {
            using (HqTrustData dbContext = new HqTrustData())
            {
                var existingEmails = dbContext.EmailAccounts.Where(b => b.InvestorId == investor.Id).ToList();

                // foreach account in existingAccounts try to find a record in investor.BankAccounts
                // if found --> update properties
                // if not found --> record was deleted by user --> remove account

                foreach (EMailAccount document in existingEmails)
                {
                    EMailAccount newDoc = investor.EMailAccounts.FirstOrDefault(b => b.Id == document.Id);
                    if (newDoc == null)
                    {
                        // not found --> remove
                        dbContext.EmailAccounts.Remove(document);
                    }
                    else
                    {
                        // found --> update properties
                        document.EmailAddress = newDoc.EmailAddress;
                        document.Salutation   = newDoc.Salutation;
                    }
                }


                foreach (EMailAccount document in investor.EMailAccounts)
                {
                    if (document.Id != 0)
                    {
                        continue;
                    }
                    document.InvestorId = investor.Id;
                    dbContext.EmailAccounts.Add(document);
                }
                try
                {
                    dbContext.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception($"Fehler beim Einfügen eines neuen Investors (Tabelle: EMailAccounts) Fehler: {ex.InnerException.Message}");
                }
            }
        }
Exemplo n.º 24
0
        protected override bool Process(Package package)
        {
            CRSMEmail    activity = package.Message;
            EMailAccount account  = package.Account;
            PXGraph      graph    = package.Graph;

            if (activity.Ticket != null ||
                activity.ParentNoteID != null ||
                account.EmailAccountType != EmailAccountTypesAttribute.Exchange ||
                !(account.IncomingProcessing ?? false))
            {
                return(false);
            }

            if (String.IsNullOrEmpty(activity.MessageId) || String.IsNullOrEmpty(activity.MessageReference))
            {
                return(false);
            }

            foreach (String id in activity.MessageReference.Split(new string[] { "> <", ">,<" }, StringSplitOptions.RemoveEmptyEntries))
            {
                string refId = id;
                if (refId.IndexOf('<') != 0)
                {
                    refId = refId.Insert(0, "<");
                }
                if (refId.LastIndexOf('>') != refId.Length - 1)
                {
                    refId = refId.Insert(refId.Length, ">");
                }

                Boolean found = false;
                foreach (CRSMEmail parent in PXSelect <CRSMEmail, Where <CRSMEmail.messageId, Like <Required <CRSMEmail.messageId> > > > .SelectSingleBound(graph, null, refId))
                {
                    activity.Ticket = parent.ID;
                    found           = true;
                    break;
                }
                if (found)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 25
0
        private void PressAccountButtonForOneEmail(string actionName, EMailAccount account)
        {
            var graph = CreateInstance <EMailAccountMaint>();

            graph.EMailAccounts.Current = account;
            var action = graph.Actions[actionName];

            if (action == null)
            {
                throw new ArgumentException(string.Format("Cannot find action '{0}' in graph '{1}'", actionName, graph.GetType().Name));
            }
            var adapter  = new PXAdapter(graph.CurrentEMailAccounts);
            var iterator = action.Press(adapter).GetEnumerator();

            while (iterator.MoveNext())
            {
            }
        }
        public EmailProcessEventArgs(PXGraph graph, EMailAccount account, CRSMEmail message)
        {
            if (graph == null)
            {
                throw new ArgumentNullException("graph");
            }
            if (account == null)
            {
                throw new ArgumentNullException("account");
            }
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            _graph   = graph;
            _account = account;
            _message = message;
        }
Exemplo n.º 27
0
            private Package(PXGraph graph, EMailAccount account, CRSMEmail message)
            {
                if (graph == null)
                {
                    throw new ArgumentNullException("graph");
                }
                if (account == null)
                {
                    throw new ArgumentNullException("account");
                }
                if (message == null)
                {
                    throw new ArgumentNullException("message");
                }

                _graph   = graph;
                _account = account;
                _message = message;
            }
Exemplo n.º 28
0
        protected virtual void EmailMessage_RowInserted(PXCache cache, PXRowInsertedEventArgs e)
        {
            var row = e.Row as EmailMessage;

            if (row == null)
            {
                return;
            }

            EMailAccount mailAccount = PXSelectJoin <EMailAccount,
                                                     LeftJoin <PreferencesEmail, On <PreferencesEmail.defaultEMailAccountID, Equal <EMailAccount.emailAccountID> > >,
                                                     Where <Match <Current <AccessInfo.userName> > >,
                                                     OrderBy <Desc <PreferencesEmail.defaultEMailAccountID, Asc <EMailAccount.address> > > >
                                       .Select(this);

            if (mailAccount != null)
            {
                row.MailAccountID = mailAccount.EmailAccountID;
            }
        }
            private MailProcessor(PXGraph graph, EMailAccount account)
            {
                if (graph == null)
                {
                    throw new ArgumentNullException("graph");
                }
                if (account == null)
                {
                    throw new ArgumentNullException("account");
                }

                string emailTagPrefix = @"\[";
                string emailTagSuffix = @"\]";

                foreach (PreferencesEmail curacc in PXSelect <PreferencesEmail> .Select(graph).RowCast <PreferencesEmail>().Where(curacc => curacc.DefaultEMailAccountID != null))
                {
                    emailTagPrefix = curacc.EmailTagPrefix;
                    emailTagSuffix = curacc.EmailTagSuffix;
                    foreach (char c in "[]()^|?*.-+")
                    {
                        string enforcedSymbol = @"\" + c.ToString();
                        emailTagPrefix = emailTagPrefix.Replace(c.ToString(), enforcedSymbol);
                        emailTagSuffix = emailTagSuffix.Replace(c.ToString(), enforcedSymbol);
                    }
                }

                string reqegx = emailTagPrefix + @"(?<Ticket>\d+?)" + emailTagSuffix;

                _tRegex  = new Regex(reqegx, RegexOptions.Multiline | RegexOptions.Compiled);
                _graph   = graph;
                _account = account;

                PXCache scache = _graph.Caches[typeof(CRActivityStatistics)];

                _graph.Views.Caches.Remove(typeof(CRActivityStatistics));
                _graph.Views.Caches.Add(typeof(CRActivityStatistics));
            }
        protected override bool Process(Package package)
        {
            CRSMEmail    activity = package.Message;
            EMailAccount account  = package.Account;
            PXGraph      graph    = package.Graph;

            if (activity.Ticket != null ||
                activity.ParentNoteID != null ||
                account.EmailAccountType != EmailAccountTypesAttribute.Exchange ||
                !(account.IncomingProcessing ?? false))
            {
                return(false);
            }

            if (String.IsNullOrEmpty(activity.MessageId) || String.IsNullOrEmpty(activity.MessageReference))
            {
                return(false);
            }

            foreach (String id in activity.MessageReference.Split(' '))
            {
                Boolean found = false;
                foreach (CRSMEmail parent in PXSelect <CRSMEmail, Where <CRSMEmail.messageId, Like <Required <CRSMEmail.messageId> > > > .SelectSingleBound(graph, null, id))
                {
                    activity.Ticket = parent.ID;
                    found           = true;
                    break;
                }
                if (found)
                {
                    return(true);
                }
            }

            return(false);
        }
        public override void changeEmail()
        {
            base.changeEmail();
            foreach (Contact copy in Contact.Select(UserProfile.Current.PKID)
                     .RowCast <Contact>()
                     .Select(contact => (Contact)Contact.Cache.CreateCopy(contact)))
            {
                copy.EMail = UserProfile.Current.Email;
                Contact.Update(copy);
            }

            foreach (EMailSyncAccount syncAccount in SyncAccount.Select(UserProfile.Current.PKID)
                     .RowCast <EMailSyncAccount>()
                     .Select(account => (EMailSyncAccount)SyncAccount.Cache.CreateCopy(account)))
            {
                syncAccount.Address = UserProfile.Current.Email;

                syncAccount.ContactsExportDate = null;
                syncAccount.ContactsImportDate = null;
                syncAccount.EmailsExportDate   = null;
                syncAccount.EmailsImportDate   = null;
                syncAccount.TasksExportDate    = null;
                syncAccount.TasksImportDate    = null;
                syncAccount.EventsExportDate   = null;
                syncAccount.EventsImportDate   = null;

                EMailAccount mailAccount = EMailAccountsNew.Select(syncAccount.EmailAccountID);
                mailAccount.Address = syncAccount.Address;

                EMailAccountsNew.Update(mailAccount);

                SyncAccount.Update(syncAccount);
            }

            Actions.PressSave();
        }
        protected void ProcessInternal(ProcessingContext context)
        {
            Dictionary <int, List <int> > processing = new Dictionary <int, List <int> >( );

            foreach (EMailSyncAccount account in context.Accounts)
            {
                List <int> list;
                if (!processing.TryGetValue(account.ServerID.Value, out list))
                {
                    processing[account.ServerID.Value] = list = new List <int>();
                }
                list.Add(account.EmployeeID.Value);
            }

            foreach (int serverID in processing.Keys)
            {
                Dictionary <string, ProcessingBox> buckets = new Dictionary <string, ProcessingBox>();

                EMailSyncServer server = null;
                foreach (PXResult <EMailSyncAccount, EMailSyncServer, EMailAccount, EPEmployee> row in
                         PXSelectJoin <EMailSyncAccount,
                                       InnerJoin <EMailSyncServer, On <EMailSyncServer.accountID, Equal <EMailSyncAccount.serverID> >,
                                                  InnerJoin <EMailAccount, On <EMailAccount.emailAccountID, Equal <EMailSyncAccount.emailAccountID> >,
                                                             LeftJoin <EPEmployee, On <EMailSyncAccount.employeeID, Equal <EPEmployee.bAccountID> > > > >,
                                       Where <EMailSyncServer.accountID, Equal <Required <EMailSyncServer.accountID> >, And <EMailSyncAccount.address, IsNotNull> >,
                                       OrderBy <Asc <EMailSyncAccount.serverID, Asc <EMailSyncAccount.employeeID> > > > .Select(this, serverID))
                {
                    server = (EMailSyncServer)row;
                    EMailSyncAccount account      = (EMailSyncAccount)row;
                    EMailAccount     eMailAccount = (EMailAccount)row;

                    if (!processing.ContainsKey(serverID) || !processing[serverID].Contains(account.EmployeeID.Value))
                    {
                        continue;
                    }

                    string address = account.Address;

                    EMailSyncPolicy policy = null;
                    if (!String.IsNullOrEmpty(account.PolicyName))
                    {
                        policy = context.Policies[account.PolicyName];
                    }
                    if (policy == null && !String.IsNullOrEmpty(server.DefaultPolicyName))
                    {
                        policy = context.Policies[server.DefaultPolicyName];
                    }
                    if (policy == null)
                    {
                        throw new PXException(Messages.EmailExchangePolicyNotFound, account.Address);
                    }

                    ProcessingBox bucket;
                    if (!buckets.TryGetValue(policy.PolicyName, out bucket))
                    {
                        buckets[policy.PolicyName] = bucket = new ProcessingBox(policy);
                    }


                    if (policy.ContactsSync ?? false)
                    {
                        bucket.Contacts.Add(
                            new PXSyncMailbox(address,
                                              account.EmployeeID.Value,
                                              account.EmailAccountID,
                                              new PXSyncMailboxPreset(account.ContactsExportDate, account.ContactsExportFolder),
                                              new PXSyncMailboxPreset(account.ContactsImportDate, account.ContactsImportFolder),
                                              eMailAccount.IncomingProcessing ?? false)
                        {
                            Reinitialize = account.ToReinitialize == true,
                            IsReset      = account.IsReset == true
                        });
                    }

                    if (policy.EmailsSync ?? false)
                    {
                        bucket.Emails.Add(
                            new PXSyncMailbox(address,
                                              account.EmployeeID.Value,
                                              account.EmailAccountID,
                                              new PXSyncMailboxPreset(account.EmailsExportDate, account.EmailsExportFolder),
                                              new PXSyncMailboxPreset(account.EmailsImportDate, account.EmailsImportFolder),
                                              eMailAccount.IncomingProcessing ?? false)
                        {
                            Reinitialize = account.ToReinitialize == true,
                            IsReset      = account.IsReset == true
                        });
                    }

                    if (policy.TasksSync ?? false)
                    {
                        bucket.Tasks.Add(
                            new PXSyncMailbox(address,
                                              account.EmployeeID.Value,
                                              account.EmailAccountID,
                                              new PXSyncMailboxPreset(account.TasksExportDate, account.TasksExportFolder),
                                              new PXSyncMailboxPreset(account.TasksImportDate, account.TasksImportFolder),
                                              eMailAccount.IncomingProcessing ?? false)
                        {
                            Reinitialize = account.ToReinitialize == true,
                            IsReset      = account.IsReset == true
                        });
                    }

                    if (policy.EventsSync ?? false)
                    {
                        bucket.Events.Add(
                            new PXSyncMailbox(address,
                                              account.EmployeeID.Value,
                                              account.EmailAccountID,
                                              new PXSyncMailboxPreset(account.EventsExportDate, account.EventsExportFolder),
                                              new PXSyncMailboxPreset(account.EventsImportDate, account.EventsImportFolder),
                                              eMailAccount.IncomingProcessing ?? false)
                        {
                            Reinitialize = account.ToReinitialize == true,
                            IsReset      = account.IsReset == true
                        });
                    }
                }
                if (server == null)
                {
                    continue;
                }

                List <Exception> errors = new List <Exception>();
                foreach (string policy in buckets.Keys)
                {
                    ProcessingBox bucket = buckets[policy];
                    using (IEmailSyncProvider provider = PXEmailSyncHelper.GetExchanger(server, bucket.Policy))
                    {
                        foreach (PXEmailSyncOperation.Operations operation in Enum.GetValues(typeof(PXEmailSyncOperation.Operations)))                        //do one time for all existing sync types
                        {
                            try
                            {
                                switch (operation)
                                {
                                case PXEmailSyncOperation.Operations.Emails:
                                    if (bucket.EmailsPending)
                                    {
                                        provider.EmailsSync(bucket.Policy, PXEmailSyncDirection.Parse(bucket.Policy.EmailsDirection), bucket.Emails);
                                    }
                                    break;

                                case PXEmailSyncOperation.Operations.Contacts:
                                    if (bucket.ContactsPending)
                                    {
                                        provider.ContactsSync(bucket.Policy, PXEmailSyncDirection.Parse(bucket.Policy.ContactsDirection), bucket.Contacts);
                                    }
                                    break;

                                case PXEmailSyncOperation.Operations.Tasks:
                                    if (bucket.TasksPending)
                                    {
                                        provider.TasksSync(bucket.Policy, PXEmailSyncDirection.Parse(bucket.Policy.TasksDirection), bucket.Tasks);
                                    }
                                    break;

                                case PXEmailSyncOperation.Operations.Events:
                                    if (bucket.EventsPending)
                                    {
                                        provider.EventsSync(bucket.Policy, PXEmailSyncDirection.Parse(bucket.Policy.EventsDirection), bucket.Events);
                                    }
                                    break;
                                }
                            }
                            catch (PXExchangeSyncItemsException ex)
                            {
                                if (bucket.Policy.SkipError == true)
                                {
                                    continue;
                                }

                                if (ex.Errors.Count > 0)
                                {
                                    foreach (string address in ex.Errors.Keys)
                                    {
                                        string message = String.Join(Environment.NewLine, ex.Errors[address].ToArray());
                                        context.StoreError(serverID, address, message);
                                    }
                                }
                            }
                            catch (PXExchangeSyncFatalException ex)
                            {
                                if (bucket.Policy.SkipError == true)
                                {
                                    continue;
                                }

                                errors.Add(new PXException(Messages.EmailExchangeSyncOperationError, operation.ToString()));
                                if (!String.IsNullOrEmpty(ex.Mailbox))
                                {
                                    context.StoreError(serverID, ex.Mailbox, ex.InnerMessage);
                                }
                                else
                                {
                                    errors.Add(ex);
                                }
                            }
                            catch (Exception ex)
                            {
                                if (bucket.Policy.SkipError == true)
                                {
                                    continue;
                                }

                                errors.Add(new PXException(Messages.EmailExchangeSyncOperationError, operation.ToString()));
                                errors.Add(ex);
                            }
                        }
                    }
                }
                if (errors.Count > 0)
                {
                    throw new PXException(String.Join(Environment.NewLine, errors.Select(e => e.Message).ToArray()));
                }
            }

            for (int index = 0; index < context.Accounts.Count; index++)
            {
                PXProcessing.SetInfo(index, ActionsMessages.RecordProcessed);
            }

            //handle exceptions
            if (context.Exceptions.Count > 0)
            {
                foreach (int index in context.Exceptions.Keys)
                {
                    List <string> errors = context.Exceptions[index];
                    if (errors == null || errors.Count < 0)
                    {
                        continue;
                    }

                    PXProcessing.SetError(index, String.Join(Environment.NewLine, errors.ToArray( )));
                }
                throw new PXException(Messages.EmailExchangeSyncFailed);
            }
        }
		private void SendCopyMessage(PXGraph graph, EMailAccount account, EPActivity message, string email)
		{
			var cache = graph.Caches[message.GetType()];
			var copy = (EPActivity)cache.CreateCopy(message);
			copy.TaskID = null;
			copy.IsIncome = false;
			copy.ParentTaskID = message.TaskID;
			copy.MailTo = email; //TODO: need add address description
			copy.MailCc = null;
			copy.MailBcc = null;
			copy.MPStatus = MailStatusListAttribute.PreProcess;
			copy.ClassID = CRActivityClass.EmailRouting;
			new AddInfoEmailProcessor().Process(new EmailProcessEventArgs(graph, account, copy));
			copy.RefNoteID = null;
			copy.ParentRefNoteID = null;
			copy.Pop3UID = null;
			copy.ImapUID = null;
			var imcUid = Guid.NewGuid();
			copy.ImcUID = imcUid;
			copy.MessageId = this.GetType().Name + "_" + imcUid.ToString().Replace("-", string.Empty);
			copy.Owner = null;
			copy = (EPActivity)cache.CreateCopy(cache.Insert(copy));
			//Update owner and reset owner if employee not found
			copy.Owner = message.Owner;
			try
			{
				cache.Update(copy);
			}
			catch (PXSetPropertyException)
			{
				copy.Owner = null;
				copy =  (EPActivity)cache.CreateCopy(cache.Update(copy));
			}
			var noteFiles = PXNoteAttribute.GetFileNotes(cache, message);
			if (noteFiles != null)
				PXNoteAttribute.SetFileNotes(cache, copy, noteFiles);
			graph.EnshureCachePersistance(copy.GetType());
		}