/// <summary>
        /// Tries to read element from XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>True if element was read.</returns>
        internal override bool TryReadElementFromXml(EwsServiceXmlReader reader)
        {
            switch (reader.LocalName)
            {
                case XmlElementNames.ExtendedFieldURI:
                    this.propertyDefinition = new ExtendedPropertyDefinition();
                    this.propertyDefinition.LoadFromXml(reader);
                    return true;
                case XmlElementNames.Value:
                    EwsUtilities.Assert(
                        this.PropertyDefinition != null,
                        "ExtendedProperty.TryReadElementFromXml",
                        "PropertyDefintion is missing");

                    string stringValue = reader.ReadElementValue();
                    this.value = MapiTypeConverter.ConvertToValue(this.PropertyDefinition.MapiType, stringValue);
                    return true;
                case XmlElementNames.Values:
                    EwsUtilities.Assert(
                        this.PropertyDefinition != null,
                        "ExtendedProperty.TryReadElementFromXml",
                        "PropertyDefintion is missing");

                    StringList stringList = new StringList(XmlElementNames.Value);
                    stringList.LoadFromXml(reader, reader.LocalName);
                    this.value = MapiTypeConverter.ConvertToValue(this.PropertyDefinition.MapiType, stringList);
                    return true;
                default:
                    return false;
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ExtendedProperty"/> class.
        /// </summary>
        /// <param name="propertyDefinition">The definition of the extended property.</param>
        internal ExtendedProperty(ExtendedPropertyDefinition propertyDefinition)
            : this()
        {
            EwsUtilities.ValidateParam(propertyDefinition, "propertyDefinition");

            this.propertyDefinition = propertyDefinition;
        }
 public ExchangeProcessor()
 {
     MailBoxFolderPath = ConfigurationManager.AppSettings["appMailBoxLocation"];
     PropertySetId = "{C11FF724-AA03-4555-9952-8FA248A11C3E}";
     MailboxExtendedPropNameInbox = "doris_mailbox_id_inbox";
     MailboxExtendedPropNameSent = "doris_mailbox_id_sent";
     CalendarExtendedPropName = "doris_calendar_id";
     MailboxExtendedPropertyDefinitionInbox = new ExtendedPropertyDefinition(new Guid(PropertySetId), MailboxExtendedPropNameInbox, MapiPropertyType.String);
     MailboxExtendedPropertyDefinitionSent = new ExtendedPropertyDefinition(new Guid(PropertySetId), MailboxExtendedPropNameSent, MapiPropertyType.String);
     CalendarExtendedPropertyDefinition = new ExtendedPropertyDefinition(new Guid(PropertySetId), CalendarExtendedPropName, MapiPropertyType.String);
 }
Ejemplo n.º 4
0
        protected override void ProcessRecord()
        {
            ExtendedPropertyDefinition extendedProperty;

            switch (this.ParameterSetName)
            {
                case "DefaultExtendedProperty":
                    extendedProperty = new ExtendedPropertyDefinition(this.DefaultExtendedProperty, this.PropertyId, this.MapiProperty);
                    break;

                default:
                    extendedProperty = new ExtendedPropertyDefinition(this.PropertyId, this.MapiProperty);
                    break;
            }

            this.WriteObject(extendedProperty);
        }
 /// <summary>
 /// Tries to load from XML.
 /// </summary>
 /// <param name="reader">The reader.</param>
 /// <param name="propertyDefinition">The property definition.</param>
 /// <returns>True if property was loaded.</returns>
 internal static bool TryLoadFromXml(EwsServiceXmlReader reader, ref PropertyDefinitionBase propertyDefinition)
 {
     switch (reader.LocalName)
     {
         case XmlElementNames.FieldURI:
             propertyDefinition = ServiceObjectSchema.FindPropertyDefinition(reader.ReadAttributeValue(XmlAttributeNames.FieldURI));
             reader.SkipCurrentElement();
             return true;
         case XmlElementNames.IndexedFieldURI:
             propertyDefinition = new IndexedPropertyDefinition(
                 reader.ReadAttributeValue(XmlAttributeNames.FieldURI),
                 reader.ReadAttributeValue(XmlAttributeNames.FieldIndex));
             reader.SkipCurrentElement();
             return true;
         case XmlElementNames.ExtendedFieldURI:
             propertyDefinition = new ExtendedPropertyDefinition();
             (propertyDefinition as ExtendedPropertyDefinition).LoadFromXml(reader);
             return true;
         default:
             return false;
     }
 }
Ejemplo n.º 6
0
        private void btnUploadConv_Click(object sender, EventArgs e)
        {
            FSWatch.EnableRaisingEvents = false;
            ImportProgressDialog ipd = new ImportProgressDialog();
            AddOwnedForm(ipd);
            //ipd.Parent = this;

            //if (listFiles.SelectedItems.Count != 0)
            //{
            ipd.Show();
            int FileCounter = 0;
            String[] FileList = Directory.GetFiles(HistorySpoolerPath);
            int FileCount = FileList.Count();

            ipd.prgImportProgress.Maximum = FileCount;

            foreach (String HistFile in FileList)
            {
                FileCounter++;

                FileInfo fi = new FileInfo(HistFile);

                ipd.prgImportProgress.Value = FileCounter;
                ipd.lblProgress.Text = String.Format("Processing file {0} of {1}...", FileCounter, FileCount);
                ipd.lblStatus.Text = String.Format("Uploading {0} ({1} bytes)...", fi.Name, fi.Length);

                if (_exchangeService == null)
                {
                    _exchangeService = new ExchangeService();

                    var store = new X509Store(StoreLocation.CurrentUser);
                    store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
                    X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindByExtension, "2.5.29.37", true);
                    _exchangeService.Url = new Uri("https://autodiscover.mail.mil/EWS/Exchange.asmx");

                    X509Certificate2Collection scollection = X509Certificate2UI.SelectFromCollection(certs, "DEE Certificate Select", "Select a certificate to connect to DISA E-mail", X509SelectionFlag.SingleSelection);

                    _exchangeService.Credentials = new ClientCertificateCredentials(scollection);
                }

                if (_imHistoryFolder == null)
                {
                    _imHistoryFolder = FindImHistoryFolder();
                }

                LyncHistoryFile lhf = new LyncHistoryFile();
                lhf.ReadFromFile(fi.FullName);
                //lhf.ReadFromFile(((FileInfo)listFiles.SelectedItems[0].Tag).FullName);

                EmailMessage ConversationItem = new EmailMessage(_exchangeService);

                //ConversationItem.MimeContent = new MimeContent("UTF-8",File.ReadAllBytes(((FileInfo)listFiles.SelectedItems[0].Tag).FullName));

                foreach(var Member in lhf._Guts.Members)
                {
                    ConversationItem.ToRecipients.Add(new EmailAddress(Member.SIPAddress));
                }

                ConversationItem.Body = lhf._Guts.HTML1;
                ConversationItem.Subject = lhf._Guts.Title;
                ConversationItem.From = new EmailAddress(lhf._Guts.Initiator.SIPAddress);

                ExtendedPropertyDefinition PR_MESSAGE_FLAGS_msgflag_read = new ExtendedPropertyDefinition(3591, MapiPropertyType.Integer);
                //ExtendedPropertyDefinition PR_RECEIPT_TIME = new ExtendedPropertyDefinition(0x002A, MapiPropertyType.SystemTime);
                ConversationItem.SetExtendedProperty(PR_MESSAGE_FLAGS_msgflag_read, 1);
                //ConversationItem.SetExtendedProperty(PR_RECEIPT_TIME, ((FileInfo)listFiles.SelectedItems[0].Tag).CreationTime);

                ConversationItem.Save(_imHistoryFolder.Id);

                if (btnLocalCopies.Checked)
                {
                    if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Documents\\LyncArchive\\"))
                    {
                        Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Documents\\LyncArchive\\");
                    }
                    try
                    {
                        File.Move(HistFile, Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Documents\\LyncArchive\\" + fi.Name);
                    }
                    catch
                    {
                        File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Documents\\LyncArchive\\" + fi.Name);
                        File.Move(HistFile, Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Documents\\LyncArchive\\" + fi.Name);
                    }
                }
                else
                {
                    File.Delete(HistFile);
                }
                //LoadConversation(((FileInfo)listFiles.SelectedItems[0].Tag).FullName);
            }

            ipd.Close();

            UpdateFileList();
            HTMLViewer.DocumentText = "";

            FSWatch.EnableRaisingEvents = true;
        }
Ejemplo n.º 7
0
        static Microsoft.Exchange.WebServices.Data.FolderId exchCreateFolder(ExchangeService service, string fldrDisplayName, Microsoft.Exchange.WebServices.Data.FolderId fldrParentID, ExtendedPropertyDefinition fldrRetentionPolicyTag, System.Guid fldrRetentionPolicyGUID, ExtendedPropertyDefinition fldrRetentionFlagTag, int fldrRetentionFlagValue)
        {
            // Verify that the paramters passed in are valid
            if (fldrDisplayName.Length == 0)
            {
                Console.WriteLine("\tError in exchCreateFolder : Invalid Folder Name");
                return null;
            }

            //Generate process output
            Console.Write("\tCreating Folder : " + fldrDisplayName + "...");

            if (service == null)
            {
                Console.WriteLine("error:Exchange Service reference Invalid");
                return null;
            }
            if (fldrParentID == null)
            {
                Console.WriteLine("error:Invalid Parent Folder");
                return null;
            }
            //if (fldrRetentionPolicyTag == null)
            //{
            //    Console.WriteLine("\t\tError in exchCreateFolder : Invalid Retention Policy Tag");
            //    return null;
            //}
            //if (fldrRetentionPolicyGUID == null)
            //{
            //    Console.WriteLine("\tError in exchCreateFolder : Invalid Retention Policy GUID");
            //    return null;
            //}

            //if (fldrRetentionFlagTag == null)
            //{
            //    Console.WriteLine("\t\tError in exchCreateFolder : Invalid Retention Policy Flag Tag");
            //    return null;
            //}

            //if (fldrRetentionFlagValue < 1)
            //{
            //    Console.WriteLine("\t\tError in exchCreateFolder : Invalid Retention Policy Flag Value");
            //    return null;
            //}

            //We have all of the inforamtion we need to make folders, create folder and assign retention policy.

            // Create Folder instance
            Folder newFolder = new Folder(service);

            try
            {
                // Assign attributes to folder and save it to exchange server
                newFolder.DisplayName = fldrDisplayName;
                if (fldrRetentionPolicyTag != null)
                {
                    Console.Write("Applying Retention Policy Tag..");
                    newFolder.SetExtendedProperty(fldrRetentionPolicyTag, fldrRetentionPolicyGUID.ToByteArray());
                    newFolder.SetExtendedProperty(fldrRetentionFlagTag, fldrRetentionFlagValue);

                }
                newFolder.Save(fldrParentID);

            }
            catch (Exception ex)
            {
                Console.WriteLine("Error : " + ex.Message);
                return null;

            }

            Console.WriteLine("success.");
            //Return the folder id reference
            return newFolder.Id;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Parses the message XML.
        /// </summary>
        /// <param name="reader">The reader.</param>
        private void ParseMessageXml(EwsServiceXmlReader reader)
        {
            do
            {
                reader.Read();

                if (reader.IsStartElement())
                {
                    switch (reader.LocalName)
                    {
                        case XmlElementNames.Value:
                            this.errorDetails.Add(reader.ReadAttributeValue(XmlAttributeNames.Name), reader.ReadElementValue());
                            break;

                        case XmlElementNames.FieldURI:
                            this.errorProperties.Add(ServiceObjectSchema.FindPropertyDefinition(reader.ReadAttributeValue(XmlAttributeNames.FieldURI)));
                            break;

                        case XmlElementNames.IndexedFieldURI:
                            this.errorProperties.Add(
                                new IndexedPropertyDefinition(
                                    reader.ReadAttributeValue(XmlAttributeNames.FieldURI),
                                    reader.ReadAttributeValue(XmlAttributeNames.FieldIndex)));
                            break;

                        case XmlElementNames.ExtendedFieldURI:
                            ExtendedPropertyDefinition extendedPropDef = new ExtendedPropertyDefinition();
                            extendedPropDef.LoadFromXml(reader);
                            this.errorProperties.Add(extendedPropDef);
                            break;

                        default:
                            break;
                    }
                }
            }
            while (!reader.IsEndElement(XmlNamespace.Messages, XmlElementNames.MessageXml));
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Removes an extended property.
 /// </summary>
 /// <param name="extendedPropertyDefinition">The extended property definition.</param>
 /// <returns>True if property was removed.</returns>
 public bool RemoveExtendedProperty(ExtendedPropertyDefinition extendedPropertyDefinition)
 {
     return this.ExtendedProperties.RemoveExtendedProperty(extendedPropertyDefinition);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Sets the extended property.
 /// </summary>
 /// <param name="extendedPropertyDefinition">The extended property definition.</param>
 /// <param name="value">The value.</param>
 public void SetExtendedProperty(ExtendedPropertyDefinition extendedPropertyDefinition, object value)
 {
     this.ExtendedProperties.SetExtendedProperty(extendedPropertyDefinition, value);
 }
Ejemplo n.º 11
0
        public void ExtendedPropertyCanBeRegistered()
        {
            var tc = new TestContainer();

            var pd = new ExtendedPropertyDefinition<int>("Grid", "Row", () => 0);

            var p = tc.ExtendedProperties.GetOrAddProperty<int>(pd);
            
            tc.ExtendedProperties["Grid.Row"].Value = 3;

            Assert.AreEqual(3, tc.ExtendedProperties["Grid.Row"].ActualValue);
        }
Ejemplo n.º 12
0
        public List<EWSCalendar> GetCalendarsAsync(int maxFoldersToRetrive, Dictionary<string, object> calendarSpecificData)
        {
            CheckCalendarSpecificData(calendarSpecificData);
            var serverSettings = GetBestSuitedExchangeServerData(ExchangeServerSettings.Domain,
                ExchangeServerSettings.EmailId, ExchangeServerSettings.Password,
                ExchangeServerSettings.UsingCorporateNetwork);
            var service = GetExchangeService(serverSettings);

            // Create a new folder view, and pass in the maximum number of folders to return.
            var view = new FolderView(1000);

            // Create an extended property definition for the PR_ATTR_HIDDEN property,
            // so that your results will indicate whether the folder is a hidden folder.
            var isHiddenProp = new ExtendedPropertyDefinition(0x10f4, MapiPropertyType.Boolean);

            // As a best practice, limit the properties returned to only those required.
            // In this case, return the folder ID, DisplayName, and the value of the isHiddenProp
            // extended property.
            view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, FolderSchema.DisplayName,
                isHiddenProp);

            // Indicate a Traversal value of Deep, so that all subfolders are retrieved.
            view.Traversal = FolderTraversal.Deep;

            // Call FindFolders to retrieve the folder hierarchy, starting with the MsgFolderRoot folder.
            // This method call results in a FindFolder call to EWS.
            var findFolderResults = service.FindFolders(WellKnownFolderName.MsgFolderRoot, view);

            var ewsCalendars = new List<EWSCalendar>();
            foreach (var searchFolder in findFolderResults.Folders)
            {
                GetCalendars(searchFolder, ewsCalendars, view);
            }
            return ewsCalendars;
        }
        public ActionResult MessageEWS(EmailAddress email)
        {
            ExchangeService service = Connection.ConnectEWS();

            //Create empty list for all mailbox messages:
            var listing = new List<EmailMessage>();

            //Create ItemView with correct pagesize and offset:
            ItemView view = new ItemView(Connection.ExPageSize, Connection.ExOffset, OffsetBasePoint.Beginning);

            view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties,
                EmailMessageSchema.Subject,
                EmailMessageSchema.DateTimeReceived,
                EmailMessageSchema.From,
                EmailMessageSchema.ToRecipients);

            view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);

            //string sf = "Body:\"Compensation\"";

            //Define the new PidTagParentDisplay property to use for filtering:
            ExtendedPropertyDefinition def = new ExtendedPropertyDefinition(0x0E05, MapiPropertyType.String);
            SearchFilter searchCriteria = new SearchFilter.IsEqualTo(def, email.Address);
            FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, searchCriteria, view);

            foreach (EmailMessage it in findResults.Items)
            {
                listing.Add(it);
            }

            return View(listing.ToList<EmailMessage>());
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="baseShape">Preview item base shape</param>
 /// <param name="additionalProperties">Additional properties (must be in form of extended properties)</param>
 public PreviewItemResponseShape(PreviewItemBaseShape baseShape, ExtendedPropertyDefinition[] additionalProperties)
 {
     this.BaseShape = baseShape;
     this.AdditionalProperties = additionalProperties;
 }
        public static FindItemsResults<Item> GetCMessages(ExchangeService service, Folder targetFolder, string[] email, int start, int length, string datefromS, string datetoS, string toS, string fromS, string subjectS, string bodyS, string dateFilter, string fromFilter, string subjectFilter)
        {
            //Create empty list for all mailbox messages:
            var listing = new List<EmailMessage>();

            Folder gsf = gsf = GetGlobalFolder(service);
            FindItemsResults<Item> findResults = null;

            //Create ItemView with correct pagesize and offset:
            ItemView view = new ItemView(length, start, OffsetBasePoint.Beginning);

            view.PropertySet = new PropertySet(EmailMessageSchema.Id,
                EmailMessageSchema.Subject,
                EmailMessageSchema.DateTimeReceived,
                EmailMessageSchema.From
                );
            view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);

            //Define the new PidTagParentDisplay property to use for filtering:
            ExtendedPropertyDefinition def = new ExtendedPropertyDefinition(0x0E05, MapiPropertyType.String);

            List<SearchFilter> searchANDFilterCollection = new List<SearchFilter>();
            List<SearchFilter> searchORcommCollection = new List<SearchFilter>();
            List<SearchFilter> searchCompCollection = new List<SearchFilter>();

            //Add "OR" commissioner search criteria:
            if (email != null && email.Count() > 0)
            {
                foreach (var target in email)
                {
                    string t = target;
                    if (target.Contains('@'))
                    {
                        t = target.Split('@')[0];
                    }

                    searchORcommCollection.Add(new SearchFilter.ContainsSubstring(def, t.ToLower()));
                    logger.Debug("Added mailbox to searchOR collection: " + target);
                }
            }

            if (searchORcommCollection.Count > 0)
            {
                SearchFilter searchOrFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchORcommCollection.ToArray());
                searchCompCollection.Add(searchOrFilter);
            }

            //Populate fields from the SEARCH form (not the filters, just the search):

            if (!string.IsNullOrWhiteSpace(datefromS))
            {
                DateTime dFrom = DateTime.Parse(datefromS + " 12:00AM");
                logger.Debug("datefromS -- " + dFrom.ToString());

                searchANDFilterCollection.Add(new SearchFilter.IsGreaterThanOrEqualTo(EmailMessageSchema.DateTimeReceived, dFrom));
            }

            if (!string.IsNullOrWhiteSpace(datetoS))
            {
                DateTime dTo = DateTime.Parse(datetoS + " 11:59PM");
                logger.Debug("datetoS -- " + dTo.ToString());
                searchANDFilterCollection.Add(new SearchFilter.IsLessThanOrEqualTo(EmailMessageSchema.DateTimeReceived, dTo));
            }

            if (!string.IsNullOrWhiteSpace(fromS))
            {
                searchANDFilterCollection.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.From, fromS));
            }

            if (!string.IsNullOrWhiteSpace(toS))
            {
                searchANDFilterCollection.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.DisplayTo, toS));
            }

            if (!string.IsNullOrWhiteSpace(subjectS))
            {
                searchANDFilterCollection.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.Subject, subjectS));
            }

            if (!string.IsNullOrWhiteSpace(bodyS))
            {
                searchANDFilterCollection.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.Body, bodyS));
            }

            //Populate fields from Datatables FILTER form (this supplements the SEARCH form):

            if (!string.IsNullOrWhiteSpace(dateFilter))
            {
                string[] dates = dateFilter.Split('~');

                if (!string.IsNullOrWhiteSpace(dates[0]))
                {
                    DateTime dfFrom = DateTime.Parse(dates[0] + " 12:00AM");
                    logger.Debug("dfFrom -- " + dfFrom.ToString());
                    searchANDFilterCollection.Add(new SearchFilter.IsGreaterThanOrEqualTo(EmailMessageSchema.DateTimeReceived, dfFrom));
                }

                if (!string.IsNullOrWhiteSpace(dates[1]))
                {
                    DateTime dfTo = DateTime.Parse(dates[1] + " 11:59PM");
                    logger.Debug("dfTo -- " + dfTo.ToString());
                    searchANDFilterCollection.Add(new SearchFilter.IsLessThanOrEqualTo(EmailMessageSchema.DateTimeReceived, dfTo));
                }
            }

            if (!string.IsNullOrWhiteSpace(fromFilter))
            {
                searchANDFilterCollection.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.From, fromFilter));
            }

            if (!string.IsNullOrWhiteSpace(subjectFilter))
            {
                searchANDFilterCollection.Add(new SearchFilter.ContainsSubstring(EmailMessageSchema.Subject, subjectFilter));
            }

            //Assemble the SearchFilter Collection

            if (searchANDFilterCollection.Count > 0)
            {
                SearchFilter searchANDFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, searchANDFilterCollection.ToArray());
                searchCompCollection.Add(searchANDFilter);
            }

            //Evaluate filters and execute find results:

            if (searchORcommCollection.Count > 0 || searchANDFilterCollection.Count > 0)
            {
                SearchFilter searchComp = new SearchFilter.SearchFilterCollection(LogicalOperator.And, searchCompCollection.ToArray());
                findResults = service.FindItems(targetFolder.Id, searchComp, view);
            }
            else
            {
                findResults = service.FindItems(targetFolder.Id, view);
            }

            logger.Debug("FindResults Count = " + findResults.TotalCount);

            return findResults;
        }