当前位置: 首页>>代码示例>>C#>>正文


C# Microsoft.Office.Interop.Outlook.Save方法代码示例

本文整理汇总了C#中Microsoft.Office.Interop.Outlook.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Outlook.Save方法的具体用法?C# Microsoft.Office.Interop.Outlook.Save怎么用?C# Microsoft.Office.Interop.Outlook.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Office.Interop.Outlook的用法示例。


在下文中一共展示了Microsoft.Office.Interop.Outlook.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConvertToRequestWithAttachment

		private Request ConvertToRequestWithAttachment(string mimefilename, string displayName, Outlook.MailItem mailItem)
		{
			// We have to save the message in order to access all its contents :(
			mailItem.Save();

			using (RedemptionMailProxy proxy = new RedemptionMailProxy(mailItem))
			{
				Email2Request email2Uro = new Email2Request(proxy);
				Request request = email2Uro.Convert(RequestChannel.Outlook, false);
				Assert.IsNotNull(request);

				//sender
				Assert.IsTrue(1 == request.Source.Items.Length, "Should only be a single source item");
				if (Environment.UserName == "lnpair")
				{
					Assert.AreEqual("[email protected]", request.Source.Items[0].Content, "Mismatch in email emailAddress");
					Assert.AreEqual("lnpair", GetPropertyValue(SMTPItemPropertyKeys.DisplayName, request.Source.Items[0].Properties), "Mismatch in email emailAddress");
					Assert.AreEqual(true.ToString(), GetPropertyValue(SMTPItemPropertyKeys.Internal, request.Source.Items[0].Properties), "Not resolved as internal");
				}

				// recipients
				Assert.AreEqual(2, request.Destination.Items.Length, "Should only be a single destination item");
				Assert.AreEqual(AddressType.To, GetPropertyValue(SMTPItemPropertyKeys.AddressType, request.Destination.Items[0].Properties  ), "Destination should be of AddressType: To");
				Assert.AreEqual("[email protected]", request.Destination.Items[0].Content, "Mismatch in email emailAddress");
				Assert.AreEqual("[email protected]", GetPropertyValue(SMTPPropertyKeys.DisplayName, request.Destination.Items[0].Properties), "Mismatch in email emailAddress");
				Assert.AreEqual("[email protected]", request.Destination.Items[1].Content, "Mismatch in email emailAddress");
				Assert.AreEqual("[email protected]", GetPropertyValue(SMTPPropertyKeys.DisplayName, request.Destination.Items[1].Properties).Trim('\''), "Mismatch in email emailAddress");
				if (Environment.UserName == "lnpair")
				{
					Assert.AreEqual(false.ToString(), GetPropertyValue(SMTPItemPropertyKeys.Internal, request.Destination.Items[1].Properties), "Not resolved as external");
				}

				//attachments
				Assert.AreEqual(1, request.Attachments.Length);
                Assert.AreEqual(displayName, request.Attachments[0].Name, "Mismatch in attachment name");
                Assert.AreEqual("application/msword; name=" + displayName, request.Attachments[0].ContentType, "Mismatch in attachment content type");
				Assert.IsTrue(!String.IsNullOrEmpty(request.Attachments[0].FileName) && File.Exists(request.Attachments[0].FileName), "Expected a vaild file");
				
				Assert.AreEqual("Outlook", GetPropertyValue(SMTPPropertyKeys.RequestChannel, request.Destination.Properties));
				Assert.AreEqual("Outlook", GetPropertyValue(SMTPPropertyKeys.RequestChannel, request.Source.Properties));

				mailItem.Delete();

				return request;
			}
		}
开发者ID:killbug2004,项目名称:WSProf,代码行数:46,代码来源:TestOutlookMail2Request.cs

示例2: SetReadyRedlineCategory

 public void SetReadyRedlineCategory(MsOutlook.MailItem mailItem)
 {
     try
     {
         if (string.IsNullOrEmpty(mailItem.Categories))
         {
             mailItem.Categories += GetReadyRedlineCategoryName();
         }
         else if (!mailItem.Categories.Contains(GetReadyRedlineCategoryName()))
         {
             mailItem.Categories += "," + GetReadyRedlineCategoryName();
         }
         mailItem.Save();
     }
     catch (System.Exception e)
     {
         Logger.LogError(e);
     }
 }
开发者ID:killbug2004,项目名称:WSProf,代码行数:19,代码来源:CategoryManagement.cs

示例3: UpdateAppointment

        /// <summary>
        /// Updates Outlook appointment from master to slave (including groups/categories)
        /// </summary>
        public void UpdateAppointment(Outlook.AppointmentItem master, ref Google.Apis.Calendar.v3.Data.Event slave)
        {
            bool updated = false;
            if (slave.Creator != null && !AppointmentSync.IsOrganizer(slave.Creator.Email)) // && AppointmentPropertiesUtils.GetGoogleOutlookAppointmentId(this.SyncProfile, slave) != null)
            {
                //ToDo:Maybe find as better way, e.g. to ask the user, if he wants to overwrite the invalid appointment
                switch (this.SyncOption)
                {
                    case SyncOption.MergeGoogleWins:
                    case SyncOption.GoogleToOutlookOnly:
                        //overwrite Outlook appointment
                        Logger.Log("Different Organizer found on Google, invitation maybe NOT sent by Outlook. Google appointment is overwriting Outlook because of SyncOption " + SyncOption + ": " + master.Subject + " - " + master.Start + ". ", EventType.Information);
                        UpdateAppointment(ref slave, master, null);
                        break;
                    case SyncOption.MergeOutlookWins:
                    case SyncOption.OutlookToGoogleOnly:
                        //overwrite Google appointment
                        Logger.Log("Different Organizer found on Google, invitation maybe NOT sent by Outlook, but Outlook appointment is overwriting Google because of SyncOption " + SyncOption + ": " + master.Subject + " - " + master.Start + ".", EventType.Information);
                        updated = true;
                        break;
                    case SyncOption.MergePrompt:
                        //promp for sync option
                        if (
                            //ConflictResolution != ConflictResolution.OutlookWinsAlways && //Shouldn't be used, because Google seems to be the master of the appointment
                            ConflictResolution != ConflictResolution.GoogleWinsAlways &&
                            ConflictResolution != ConflictResolution.SkipAlways)
                        {
                            var r = new ConflictResolver();
                            ConflictResolution = r.Resolve("Cannot update appointment from Outlook to Google because different Organizer found on Google, invitation maybe NOT sent by Outlook: \"" + master.Subject + " - " + master.Start + "\". Do you want to update it back from Google to Outlook?", slave, master, this);
                        }
                        switch (ConflictResolution)
                        {
                            case ConflictResolution.Skip:
                            case ConflictResolution.SkipAlways: //Skip
                                SkippedCount++;
                                Logger.Log("Skipped Updating appointment from Outlook to Google because different Organizer found on Google, invitation maybe NOT sent by Outlook: \"" + master.Subject + " - " + master.Start + "\".", EventType.Information);
                                break;
                            case ConflictResolution.GoogleWins:
                            case ConflictResolution.GoogleWinsAlways: //Keep Google and overwrite Outlook
                                UpdateAppointment(ref slave, master, null);
                                break;
                            case ConflictResolution.OutlookWins:
                            case ConflictResolution.OutlookWinsAlways: //Keep Outlook and overwrite Google
                                updated = true;
                                break;
                            default:
                                throw new ApplicationException("Cancelled");
                        }

                        break;
                }
            }
            else //Only update, if invitation was not sent on Google side or freshly created during this sync
                updated = true;

            //if (master.Recipients.Count == 0 ||
            //    master.Organizer == null ||
            //    AppointmentSync.IsOrganizer(AppointmentSync.GetOrganizer(master), master)||
            //    slave.Id.Uri == null
            //    )
            //{//Only update, if this appointment was organized on Outlook side or freshly created during this sync

            if (updated)
            {
                AppointmentSync.UpdateAppointment(master, slave);

                if (slave.Creator == null || AppointmentSync.IsOrganizer(slave.Creator.Email))
                {
                    AppointmentPropertiesUtils.SetGoogleOutlookAppointmentId(SyncProfile, slave, master);
                    slave = SaveGoogleAppointment(slave);
                }

                //ToDo: Doesn'T work for newly created recurrence appointments before save, because Event.Reminder is throwing NullPointerException and Reminders cannot be initialized, therefore moved to after saving
                //if (slave.Recurrence != null && slave.Reminders != null)
                //{

                //    if (slave.Reminders.Overrides != null)
                //    {
                //        slave.Reminders.Overrides.Clear();
                //        if (master.ReminderSet)
                //        {
                //            var reminder = new Google.Apis.Calendar.v3.Data.EventReminder();
                //            reminder.Minutes = master.ReminderMinutesBeforeStart;
                //            if (reminder.Minutes > 40300)
                //            {
                //                //ToDo: Check real limit, currently 40300
                //                Logger.Log("Reminder Minutes to big (" + reminder.Minutes + "), set to maximum of 40300 minutes for appointment: " + master.Subject + " - " + master.Start, EventType.Warning);
                //                reminder.Minutes = 40300;
                //            }
                //            reminder.Method = "popup";
                //            slave.Reminders.Overrides.Add(reminder);
                //        }
                //    }
                //    slave = SaveGoogleAppointment(slave);
                //}

                AppointmentPropertiesUtils.SetOutlookGoogleAppointmentId(this, master, slave);
//.........这里部分代码省略.........
开发者ID:kcarnold,项目名称:googlesyncmod,代码行数:101,代码来源:Synchronizer.cs

示例4: SaveOutlookPhoto

        //public void SaveOutlookPhoto(ContactMatch match)
        //{
        //    bool hasGooglePhoto = Utilities.HasPhoto(match.GoogleContact);
        //    bool hasOutlookPhoto = Utilities.HasPhoto(match.OutlookContact);
        //    if (hasGooglePhoto)
        //    {
        //        Image image = new Image(match.GoogleContact.PhotoUri);
        //        Utilities.SetOutlookPhoto(match.OutlookContact, image);
        //        ContactPropertiesUtils.SetOutlookGoogleContactId(this, match.OutlookContact, match.GoogleContact);
        //        match.OutlookContact.Save();
        //        //googlePhoto.Dispose();
        //    }
        //    else if (hasOutlookPhoto)
        //    {
        //        match.OutlookContact.RemovePicture();
        //        ContactPropertiesUtils.SetOutlookGoogleContactId(this, match.OutlookContact, match.GoogleContact);
        //        match.OutlookContact.Save();
        //    }
        //}
        //public void SaveGooglePhoto(ContactMatch match)
        //{
        //    bool hasGooglePhoto = Utilities.HasPhoto(match.GoogleContact);
        //    bool hasOutlookPhoto = Utilities.HasPhoto(match.OutlookContact);
        //    if (hasOutlookPhoto)
        //    {
        //        // add outlook photo to google
        //        Image outlookPhoto = Utilities.GetOutlookPhoto(match.OutlookContact);
        //        if (outlookPhoto != null)
        //        {
        //            //outlookPhoto = Utilities.CropImageGoogleFormat(outlookPhoto);
        //            bool saved = Utilities.SaveGooglePhoto(this, match.GoogleContact, outlookPhoto);
        //            if (!saved)
        //                throw new Exception("Could not save");
        //            //Just save the Outlook Contact to have the same lastUpdate date as Google
        //            ContactPropertiesUtils.SetOutlookGoogleContactId(this, match.OutlookContact, match.GoogleContact);
        //            match.OutlookContact.Save();
        //            outlookPhoto.Dispose();
        //        }
        //    }
        //    else if (hasGooglePhoto)
        //    {
        //        //ToDo: Delete Photo on Google side, if no Outlook photo exists
        //        //match.GoogleContact.PhotoUri = null;
        //    }
        //    //Utilities.DeleteTempPhoto();
        //}
        public void SaveOutlookPhoto(Contact googleContact, Outlook.ContactItem outlookContact)
        {
            bool hasGooglePhoto = Utilities.HasPhoto(googleContact);
            bool hasOutlookPhoto = Utilities.HasPhoto(outlookContact);

            if (hasGooglePhoto)
            {
                // add google photo to outlook
                //ToDo: add google photo to outlook with new Google API
                //Stream stream = _googleService.GetPhoto(match.GoogleContact);
                Image googlePhoto = Utilities.GetGooglePhoto(this, googleContact);
                if (googlePhoto != null)    // Google may have an invalid photo
                {
                    Utilities.SetOutlookPhoto(outlookContact, googlePhoto);
                    ContactPropertiesUtils.SetOutlookGoogleContactId(this, outlookContact, googleContact);
                    outlookContact.Save();

                    googlePhoto.Dispose();
                }
            }
            else if (hasOutlookPhoto)
            {
                outlookContact.RemovePicture();
                ContactPropertiesUtils.SetOutlookGoogleContactId(this, outlookContact, googleContact);
                outlookContact.Save();
            }
        }
开发者ID:kcarnold,项目名称:googlesyncmod,代码行数:73,代码来源:Synchronizer.cs

示例5: SaveGooglePhoto

        //public void SaveContactPhotos(ContactMatch match)
        //{
        //    bool hasGooglePhoto = Utilities.HasPhoto(match.GoogleContact);
        //    bool hasOutlookPhoto = Utilities.HasPhoto(match.OutlookContact);
        //    if (!hasGooglePhoto && !hasOutlookPhoto)
        //        return;
        //    else if (hasGooglePhoto && _syncOption != SyncOption.OutlookToGoogleOnly)
        //    {
        //        // add google photo to outlook
        //        Image googlePhoto = Utilities.GetGooglePhoto(this, match.GoogleContact);
        //        Utilities.SetOutlookPhoto(match.OutlookContact, googlePhoto);
        //        match.OutlookContact.Save();
        //        googlePhoto.Dispose();
        //    }
        //    else if (hasOutlookPhoto && _syncOption != SyncOption.GoogleToOutlookOnly)
        //    {
        //        // add outlook photo to google
        //        Image outlookPhoto = Utilities.GetOutlookPhoto(match.OutlookContact);
        //        if (outlookPhoto != null)
        //        {
        //            outlookPhoto = Utilities.CropImageGoogleFormat(outlookPhoto);
        //            bool saved = Utilities.SaveGooglePhoto(this, match.GoogleContact, outlookPhoto);
        //            if (!saved)
        //                throw new Exception("Could not save");
        //            outlookPhoto.Dispose();
        //        }
        //    }
        //    else
        //    {
        //        // TODO: if both contacts have photos and one is updated, the
        //        // other will not be updated.
        //    }
        //    //Utilities.DeleteTempPhoto();
        //}
        public void SaveGooglePhoto(ContactMatch match, Outlook.ContactItem outlookContactitem)
        {
            bool hasGooglePhoto = Utilities.HasPhoto(match.GoogleContact);
            bool hasOutlookPhoto = Utilities.HasPhoto(outlookContactitem);

            if (hasOutlookPhoto)
            {
                // add outlook photo to google
                Image outlookPhoto = Utilities.GetOutlookPhoto(outlookContactitem);

                if (outlookPhoto != null)
                {
                    //Try up to 5 times to overcome Google issue
                    for (int retry = 0; retry < 5; retry++)
                    {
                        try
                        {

                            using (MemoryStream stream = new MemoryStream(Utilities.BitmapToBytes(new Bitmap(outlookPhoto))))
                            {
                                // Save image to stream.
                                //outlookPhoto.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);

                                //Don'T crop, because maybe someone wants to keep his photo like it is on Outlook
                                //outlookPhoto = Utilities.CropImageGoogleFormat(outlookPhoto);
                                ContactsRequest.SetPhoto(match.GoogleContact, stream);

                                //Just save the Outlook Contact to have the same lastUpdate date as Google
                                ContactPropertiesUtils.SetOutlookGoogleContactId(this, outlookContactitem, match.GoogleContact);
                                outlookContactitem.Save();
                                outlookPhoto.Dispose();

                            }

                            break; //Exit because photo save succeeded
                        }
                        catch (GDataRequestException ex)
                        { //If Google found a picture for a new Google account, it sets it automatically and throws an error, if updating it with the Outlook photo.
                            //Therefore save it again and try again to save the photo
                            if (retry == 4)
                                ErrorHandler.Handle(new Exception("Photo of contact " + match.GoogleContact.Title + "couldn't be saved after 5 tries, maybe Google found its own photo and doesn't allow updating it", ex));
                            else
                            {
                                System.Threading.Thread.Sleep(1000);
                                //LoadGoogleContact again to get latest ETag
                                //match.GoogleContact = LoadGoogleContacts(match.GoogleContact.AtomEntry.Id);
                                match.GoogleContact = SaveGoogleContact(match.GoogleContact);
                            }
                        }
                    }
                }
            }
            else if (hasGooglePhoto)
            {
                //Delete Photo on Google side, if no Outlook photo exists
                ContactsRequest.Delete(match.GoogleContact.PhotoUri, match.GoogleContact.PhotoEtag);
            }

            Utilities.DeleteTempPhoto();
        }
开发者ID:kcarnold,项目名称:googlesyncmod,代码行数:94,代码来源:Synchronizer.cs

示例6: ResetMatch

        /// <summary>
        /// Reset the match link between Outlook and Google appointment
        /// </summary>
        public void ResetMatch(Outlook.AppointmentItem outlookAppointment)
        {
            if (outlookAppointment != null)
            {
                //try
                //{
                AppointmentPropertiesUtils.ResetOutlookGoogleAppointmentId(this, outlookAppointment);
                outlookAppointment.Save();
                //}
                //finally
                //{
                //    Marshal.ReleaseComObject(OutlookAppointment);
                //    OutlookAppointment = null;
                //}

            }
        }
开发者ID:kcarnold,项目名称:googlesyncmod,代码行数:20,代码来源:Synchronizer.cs

示例7: GetFirstScanId

        public static string GetFirstScanId(Outlook.MailItem item)
        {
            var firstScanEntry = item.UserProperties.Find("ConversationEntryId");

            if (firstScanEntry == null)
            {
                firstScanEntry = item.UserProperties.Add("ConversationEntryId", Outlook.OlUserPropertyType.olText, true, missing);
                firstScanEntry.Value = item.ConversationIndex.Substring(0,44);
                item.Save();
                return item.ConversationIndex.Substring(0, 44);
            }
            return (string)firstScanEntry.Value;
        }
开发者ID:alpagas,项目名称:outlook-addin,代码行数:13,代码来源:MailManager.cs

示例8: SetIOfficeProperties

        private static void SetIOfficeProperties(Guid documentGuid, Outlook.MailItem mailItem)
        {
            // Til visning (Ny property IOffice kender den ikke)
            var isArchivedProperty = EnsureProperty(mailItem, Constants.MailItemProperty_IsArchived, Outlook.OlUserPropertyType.olYesNo, Microsoft.Office.Interop.Outlook.OlFormatYesNo.olFormatYesNoIcon);
            isArchivedProperty.Value = true;

            // IOffice native fields
            var documentGuidProperty = EnsureProperty(mailItem, Constants.MailItemProperty_DocGuid, Outlook.OlUserPropertyType.olText);
            documentGuidProperty.Value = documentGuid.ToString();

            var sentFromIOfficeProperty = EnsureProperty(mailItem, Constants.MailItemProperty_DocSentFromIoffice, Outlook.OlUserPropertyType.olYesNo);
            sentFromIOfficeProperty.Value = true;

            var archivedProperty = EnsureProperty(mailItem, Constants.MailItemProperty_Archived, Outlook.OlUserPropertyType.olText);
            archivedProperty.Value = "Attempted";

            mailItem.Save();
        }
开发者ID:NephelimDK,项目名称:IOfficeConnect,代码行数:18,代码来源:IOfficeConnectGlobals+(TERMINAL01s+modstridende+kopi+2015-05-07).cs

示例9: mailItem_Close

        /// <summary>
        /// WrapperEvent fired when a mailItem is closed.
        /// </summary>
        /// <param name="mailItem">the mailItem to close</param>
        /// <param name="Cancel">False when the event occurs. If the event procedure sets this argument to True,
        /// the open operation is not completed and the inspector is not displayed.</param>
        void mailItem_Close(Outlook.MailItem mailItem, ref bool Cancel)
        {
            try
            {
                if (mailItem == null)
                    return;

                // New mail (Compose)
                if (mailItem.Sent == false)
                {
                    bool toSave = false;
                    var SignProperpty = GetProperty(mailItem, "GnuPGSetting.Sign");
                    if (SignProperpty == null || (bool)SignProperpty != ribbon.SignButton.Checked)
                    {
                        toSave = true;
                    }

                    var EncryptProperpty = GetProperty(mailItem, "GnuPGSetting.Decrypted");
                    if (EncryptProperpty == null || (bool)EncryptProperpty != ribbon.EncryptButton.Checked)
                    {
                        toSave = true;
                    }
                    if (toSave == true)
                    {
            #if DISABLED
            BoolEventArgs ev = e as BoolEventArgs;
            DialogResult res = MessageBox.Show("Do you want to save changes?",
                                           "OutlookGnuPG",
                                           MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
            if (res == DialogResult.Yes)
            {
              // Must call mailItem.Write event handler (mailItem_Save) explicitely as it is not always called
              // from the mailItem.Save() method. Mail is effectly saved only if a property changed.
              mailItem_Save(sender, EventArgs.Empty);
              mailItem.Save();
            }
            if (res == DialogResult.Cancel)
            {
              ev.Value = true;
            }
            #else
                        // Invalidate the mailItem to force Outlook to ask to save the mailItem, hence calling
                        // the mailItem_Save() handler to record the buttons state.
                        // Note: the reason (button state property change) to save the mailItem is not necessairy obvious
                        // to the user, certainly if nothing has been updated/changed by the user. If specific notification
                        // is required see DISABLED code above. Beware, it might open 2 dialog boxes: the add-in custom and
                        // the regular Outlook save confirmation.
                        mailItem.Subject = mailItem.Subject;
                    }
            #endif
                }
                else
                {
                    var SignProperty = GetProperty(mailItem, "GnuPGSetting.Decrypted");
                    if (SignProperty != null && (bool)SignProperty)
                    {
                        mailItem.Close(Microsoft.Office.Interop.Outlook.OlInspectorClose.olDiscard);
                    }
                }
            }
            catch
            {
                // Ignore random COM errors
            }
        }
开发者ID:ktw,项目名称:OutlookPrivacyPlugin,代码行数:71,代码来源:OutlookPrivacyPlugin.cs

示例10: mailItem_Close

		/// <summary>
		/// WrapperEvent fired when a mailItem is closed.
		/// </summary>
		/// <param name="mailItem">the mailItem to close</param>
		/// <param name="Cancel">False when the event occurs. If the event procedure sets this argument to True,
		/// the open operation is not completed and the inspector is not displayed.</param>
		void mailItem_Close(Outlook.MailItem mailItem, ref bool Cancel)
		{
			try
			{
				if (mailItem == null)
					return;

				// New mail (Compose)
				if (mailItem.Sent == false)
				{
					var toSave = false;
					var signProperpty = GetProperty(mailItem, "GnuPGSetting.Sign", false);
					if (signProperpty == null || (bool)signProperpty != _ribbon.SignButton.Checked)
					{
						toSave = true;
					}

					var encryptProperpty = GetProperty(mailItem, "GnuPGSetting.Decrypted", false);
					if (encryptProperpty == null || (bool)encryptProperpty != _ribbon.EncryptButton.Checked)
					{
						toSave = true;
					}

                    SetProperty(mailItem, "GnuPGSetting.Sign", false);
                    SetProperty(mailItem, "GnuPGSetting.Encrypt", false);

					if (toSave == true)
					{
#if DISABLED
		BoolEventArgs ev = e as BoolEventArgs;
		DialogResult res = MessageBox.Show("Do you want to save changes?",
										   "OutlookGnuPG",
										   MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
		if (res == DialogResult.Yes)
		{
		  // Must call mailItem.Write event handler (mailItem_Save) explicitely as it is not always called
		  // from the mailItem.Save() method. Mail is effectly saved only if a property changed.
		  mailItem_Save(sender, EventArgs.Empty);
		  mailItem.Save();
		}
		if (res == DialogResult.Cancel)
		{
		  ev.Value = true;
		}
#else
						// Invalidate the mailItem to force Outlook to ask to save the mailItem, hence calling
						// the mailItem_Save() handler to record the buttons state.
						// Note: the reason (button state property change) to save the mailItem is not necessairy obvious
						// to the user, certainly if nothing has been updated/changed by the user. If specific notification
						// is required see DISABLED code above. Beware, it might open 2 dialog boxes: the add-in custom and
						// the regular Outlook save confirmation.
						mailItem.Subject = mailItem.Subject;
					}
#endif
				}
				else
				{
                    SetProperty(mailItem, "GnuPGSetting.Sign", false);
                    SetProperty(mailItem, "GnuPGSetting.Encrypt", false);

                    var signProperty = GetProperty(mailItem, "GnuPGSetting.Decrypted");
                    SetProperty(mailItem, "GnuPGSetting.Decrypted", false);

                    if (signProperty != null && (bool)signProperty)
					{
                        // NOTE: Cannot call mailItem.Close from Close event handler
                        //       instead we will start a timer and call it after we
                        //       return. There is a small race condition, but 250
                        //       milliseconds should be enough even on slow machines.

                        var timer = new Timer { Interval = 250 };
                        timer.Tick += new EventHandler((o, e) =>
						{
                            timer.Stop();
                            mailItem.Close(
								_settings.SaveDecrypted ? Outlook.OlInspectorClose.olSave : Outlook.OlInspectorClose.olDiscard);
                        });

					    timer.Start();

						Cancel = true;
					}
				}
			}
			catch
			{
				// Ignore random COM errors
			}
		}
开发者ID:ALange,项目名称:OutlookPrivacyPlugin,代码行数:95,代码来源:OutlookPrivacyPlugin.cs

示例11: mailItem_Open


//.........这里部分代码省略.........

						while (true)
						{
							if (indexes.Count == 0)
								break;

							int index = indexes.Pop();
							body.Remove(index, 1);
						}

						mailItem.Body = body.ToString();
						//mailItem.Save();
					}

					_autoDecrypt = false;
					DecryptEmail(mailItem);
					// Update match again, in case decryption failed/cancelled.
					match = Regex.Match(mailItem.Body, _pgpNoReplyHeaderPattern, RegexOptions.Multiline);

					SetProperty(mailItem, "GnuPGSetting.Decrypted", true);
				}
				else if (match != null && _settings.AutoVerify && match.Groups[1].Value == _pgpSignedHeader)
				{
					VerifyEmail(mailItem);
				}
				else
				{
					var foundPgpMime = false;
					var sigHash = "sha1";
					Outlook.Attachment encryptedMime = null;
					Outlook.Attachment sigMime = null;

					var contentType = ReadContentType(mailItem);

					logger.Trace("MIME: Message content-type: " + (string)contentType);

					if (contentType.Contains("application/pgp-signature"))
					{
						// PGP MIM Signed message it looks like
						//multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Iq9CNK2GBN9g0PCsVJK4WdkEAR0887CbX"; charset="iso-8859-1"

						logger.Trace("MIME: Found application/pgp-signature: " + contentType);

						var sigMatch = Regex.Match((string)contentType, @"micalg=pgp-([^; ]*)");
						sigHash = sigMatch.Groups[1].Value;

						logger.Trace("MIME: sigHash: " + sigHash);
					}

					// Look for PGP MIME
					foreach (Outlook.Attachment attachment in mailItem.Attachments)
					{
						var mimeEncoding = attachment.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x370E001F");

						logger.Trace("MIME: Attachment type: " + mimeEncoding);

						if (mimeEncoding == "application/pgp-encrypted")
						{
							logger.Trace("MIME: Found application/pgp-encrypted.");
							foundPgpMime = true;
						}
						else if (mimeEncoding == "application/pgp-signature")
						{
							logger.Trace("MIME: Found application/pgp-signature");
							sigMime = attachment;
						}
						else if (foundPgpMime && encryptedMime == null && mimeEncoding == "application/octet-stream")
						{
							// Should be first attachment *after* PGP_MIME version identification

							logger.Trace("MIME: Found octet-stream following pgp-encrypted.");
							encryptedMime = attachment;
						}
					}

					if (encryptedMime != null || sigMime != null)
					{
						logger.Trace("MIME: Calling HandlePgpMime");
						HandlePgpMime(mailItem, encryptedMime, sigMime, sigHash);

						if(encryptedMime != null)
							SetProperty(mailItem, "GnuPGSetting.Decrypted", true);
					}
				}

				if (match != null)
				{
					_ribbon.VerifyButton.Enabled = (match.Groups[1].Value == _pgpSignedHeader);
					_ribbon.DecryptButton.Enabled = (match.Groups[1].Value == _pgpEncryptedHeader);
				}

				if(_ribbon.VerifyButton.Enabled || _ribbon.DecryptButton.Enabled)
				{
					if (_settings.SaveDecrypted)
						mailItem.Save();
				}
			}

			_ribbon.InvalidateButtons();
		}
开发者ID:ALange,项目名称:OutlookPrivacyPlugin,代码行数:101,代码来源:OutlookPrivacyPlugin.cs

示例12: PostAttachments

        public static bool PostAttachments(Outlook.MailItem item, Account account, EcsConfiguration configuration,
            string encryptKey, string recips, ref List<string> pointers, OutlookWin32Window win, bool noPlaceholder)
        {
            const string SOURCE = CLASS_NAME + "PostAttachments";
            try
            {
                //get the bytes for the placeholder text
                var placeholder = Encoding.UTF8.GetBytes(Resources.placeholder_text);
                SafeMailItem safMail;
                try
                {
                    safMail = RedemptionLoader.new_SafeMailItem();
                }
                catch (Exception ex)
                {
                    Logger.Error(SOURCE, String.Format(
                        "unable to work with attachments for {0}, failed to instantiate SafeMailItem: {1}",
                        item.Subject, ex.Message));
                    return false;
                }
                //need to save the item first before we can work with the SafeMailItem
                item.Save();
                safMail.Item = item;
                var colAttach = safMail.Attachments;
                /* Outlook will move any embedded images to the head of the attachments table
                * if that's the case then we need to remove and re-add the other attachments
                * so that the pointer list will match the finished order
                */
                var hidden = false;
                string contentId;
                var savedAttach = new Dictionary<int, byte[]>();
                //do we have any embedded images?
                foreach (Redemption.Attachment rdoAttach in colAttach)
                {
                    GetAttachProps(rdoAttach, out contentId, out hidden);
                    if (hidden) break;
                }
                if (hidden)
                {
                    //walk through in reverse order
                    //delete and reattach each non-hidden attachment
                    for (var i = colAttach.Count; i > 0; i--)
                    {
                        Redemption.Attachment rdoAttach = colAttach[i];
                        GetAttachProps(rdoAttach, out contentId, out hidden);
                        if (hidden) continue;
                        if (rdoAttach.Type.Equals(5)) //embedded
                        {
                            var msg = rdoAttach.EmbeddedMsg;
                            rdoAttach.Delete();
                            colAttach.Add(msg, 5);
                        }
                        else
                        {
                            var path = Path.Combine(Path.GetTempPath(), "ChiaraMail", rdoAttach.FileName);
                            var displayName = rdoAttach.DisplayName;
                            if (File.Exists(path)) File.Delete(path);
                            rdoAttach.SaveAsFile(path);
                            rdoAttach.Delete();
                            rdoAttach = colAttach.Add(path, 1, Type.Missing, displayName);
                            //get the bytes and drop those in the dictionary, linked to the current index
                            savedAttach.Add(rdoAttach.Index, File.ReadAllBytes(path));
                            File.Delete(path);
                        }
                    }
                }

                //now loop through and collect the content (except for embedded messages)
                var attachList = new List<Attachment>();
                bool showForm = false;
                foreach (Redemption.Attachment rdoAttach in colAttach)
                {
                    var attach = new Attachment { Type = rdoAttach.Type };
                    switch (rdoAttach.Type)
                    {
                        case (int)Outlook.OlAttachmentType.olEmbeddeditem:
                            //is this an ECS attachment?
                            var msg = rdoAttach.EmbeddedMsg;
                            if (HasChiaraHeader(msg))
                            {
                                ForwardEmbeddedECS(msg, recips, account);
                            }
                            //always add
                            attachList.Add(attach);
                            break;
                        case (int)Outlook.OlAttachmentType.olByReference:
                        case (int)Outlook.OlAttachmentType.olOLE:
                            attachList.Add(attach);
                            break;
                        case (int)Outlook.OlAttachmentType.olByValue:
                            showForm = true;
                            //we may have already gotten the bytes
                            if (savedAttach.Count > 0 && savedAttach.ContainsKey(rdoAttach.Index))
                            {
                                attach.Content = savedAttach[rdoAttach.Index];
                            }
                            if (attach.Content == null || attach.Content.Length == 0)
                            {
                                //try just read the bytes from the binary property
                                //this could fail if the attachment is too big
//.........这里部分代码省略.........
开发者ID:ProjectECS,项目名称:ECS,代码行数:101,代码来源:Utils.cs

示例13: GetEmbeddedImages

 public static IEnumerable<Attachment> GetEmbeddedImages(Outlook.MailItem item)
 {
     const string SOURCE = CLASS_NAME + "GetEmbeddedImages";
     var list = new List<Attachment>();
     SafeMailItem safMail;
     try
     {
         safMail = RedemptionLoader.new_SafeMailItem();
     }
     catch (Exception ex)
     {
         Logger.Error(SOURCE, string.Format(
             "unable to work with attachments for {0}, failed to instantiate SafeMailItem: {1}",
             item.Subject, ex.Message));
         return list;
     }
     //need to save the item first before we can work with the SafeMailItem
     item.Save();
     safMail.Item = item;
     var colAttach = safMail.Attachments;
     //walk down the existing
     foreach (Redemption.Attachment rdoAttach in colAttach)
     {
         string contentId;
         bool hidden;
         GetAttachProps(rdoAttach, out contentId, out hidden);
         if (string.IsNullOrEmpty(contentId)) continue;
         try
         {
             //could fail if attachment is too big
             var content = rdoAttach.AsArray != null
                 ? rdoAttach.AsArray as byte[]
                 : null; //.Fields[ThisAddIn.PR_ATTACH_DATA_BIN]);
             if (content == null) continue;
             {
                 list.Add(new Attachment
                 {
                     Content = content,
                     ContentId = contentId,
                     Name = rdoAttach.FileName,
                     Index = rdoAttach.Index
                 });
             }
         }
         catch
         {
             Logger.Warning(SOURCE,
                            "failed to retrieve content from embedded image");
         }
     }
     return list;
 }
开发者ID:ProjectECS,项目名称:ECS,代码行数:52,代码来源:Utils.cs

示例14: CreateOutlookNoteAndSyncToGoogle

        private void CreateOutlookNoteAndSyncToGoogle(out Outlook.NoteItem outlookNote, out NoteMatch match)
        {
            //ToDo: Check for eache SyncOption and SyncDelete combination
            sync.SyncOption = SyncOption.MergeOutlookWins;
            sync.SyncDelete = true;

            // create new contact to sync
            // create new note to sync
            outlookNote = Synchronizer.CreateOutlookNoteItem(Synchronizer.SyncNotesFolder);
            outlookNote.Body = body;
            outlookNote.Categories = groupName;
            outlookNote.Save();

            //Outlook note should now have a group
            Assert.AreEqual(groupName, outlookNote.Categories);

            Document googleNote = new Document();
            googleNote.Type = Document.DocumentType.Document;
            sync.UpdateNote(outlookNote, googleNote);
            match = new NoteMatch(outlookNote, googleNote);

            //save Notes
            sync.SaveNote(match);

            for (int i = 0; match.AsyncUpdateCompleted.HasValue && !match.AsyncUpdateCompleted.Value && i < 100; i++)
                Thread.Sleep(1000);//DoNothing, until the Async Update is complete, but only wait maximum 10 seconds

            //load the same note from google.
            sync.MatchNotes();
            match = FindMatch(outlookNote);

            // google contact should now have the same group
            Assert.IsNotNull(match.GoogleNote.ParentFolders);
            //Assert.Greater(match.GoogleNote.ParentFolders.Count, 0);
            Assert.AreEqual(2, match.GoogleNote.ParentFolders.Count);   //2 because Notes folder and the category folder

            Document categoryFolder = null;
            foreach (string uri in match.GoogleNote.ParentFolders)
            {
                Document folder = sync.GetGoogleFolder(null, null, uri);
                if (folder.Title == groupName)
                {
                    categoryFolder = folder;
                    break;
                }
            }
            Assert.IsNotNull(categoryFolder);
        }
开发者ID:kcarnold,项目名称:googlesyncmod,代码行数:48,代码来源:SyncNotesTests.cs

示例15: convertTextToUrlInMail

        /// <summary>
        /// Converts matches from pattern to links.
        /// </summary>
        /// <param name="mail"></param>
        private void convertTextToUrlInMail(Outlook.MailItem mail)
        {
            string str = "";
            string url;
            Regex reg = null;
            StringBuilder pattern = new StringBuilder();

            pattern = CreateRegexPatternFromSettingsPrefixes();

            str = mail.HTMLBody;
            url = Properties.Settings.Default.JiraURLConverterURL ?? "";

            reg = new Regex(pattern.ToString(), RegexOptions.IgnoreCase);
            string qwerty = reg.Replace(str, "<a href='" + url + "'>$1</a>");

            mail.HTMLBody = qwerty;
            mail.Save();
        }
开发者ID:Bjeorn,项目名称:OutlookAddinJiraUrlConverter,代码行数:22,代码来源:ThisAddIn.cs


注:本文中的Microsoft.Office.Interop.Outlook.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。