コード例 #1
0
        /// <summary>
        ///     Sends the acceptance.
        /// </summary>
        /// <param name="calendar">The calendar.</param>
        /// <param name="iCalMessage">The i cal message.</param>
        /// <param name="eventEmail">The event email.</param>
        private static void SendAcceptance(IICalendar calendar, ReceivedICalEmailMessage iCalMessage, EventEmail eventEmail)
        {
            Inbox inbox = iCalMessage.FromInbox;

            string subject = string.Format("{0}: {1}", GlobalStrings.Accepted, iCalMessage.EmSubject ?? GlobalStrings.MeetingInvitation);

            /////
            // Create the new mail message.
            /////
            var sentMessage = new SentICalEmailMessage
            {
                Name            = subject,
                EmFrom          = inbox.InboxEmailAddress,
                EmTo            = iCalMessage.EmFrom,
                EmSubject       = subject,
                EmBody          = iCalMessage.EmBody ?? string.Empty,
                EmIsHtml        = iCalMessage.EmIsHtml ?? true,
                OwnerEventEmail = eventEmail
            };

            sentMessage.Save( );

            var emailServerSettings = Entity.Get <TenantEmailSetting>("core:tenantEmailSettingsInstance");

            iCalEmailHelper.SendICalEmail(calendar, sentMessage.As <SentEmailMessage>( ).ToMailMessage( ), emailServerSettings);
        }
コード例 #2
0
        /// <summary>
        ///     Creates the and send acceptance.
        /// </summary>
        /// <param name="calendar">The calendar.</param>
        /// <param name="iCalMessage">The i cal message.</param>
        /// <param name="eventEmail">The event email.</param>
        private static void CreateAndSendAcceptance(IICalendar calendar, ReceivedICalEmailMessage iCalMessage, EventEmail eventEmail)
        {
            if (calendar == null || iCalMessage == null)
            {
                return;
            }

            IICalendar reply = CreateAcceptance(calendar, iCalMessage);

            if (reply != null)
            {
                SendAcceptance(reply, iCalMessage, eventEmail);
            }
        }
コード例 #3
0
        /// <summary>
        ///     Creates the acceptance.
        /// </summary>
        /// <param name="calendar">The calendar.</param>
        /// <param name="iCalMessage">The i cal message.</param>
        /// <returns></returns>
        private static IICalendar CreateAcceptance(IICalendar calendar, ReceivedICalEmailMessage iCalMessage)
        {
            /////
            // Sanity check on the calendar and message.
            /////
            if (calendar == null || iCalMessage == null)
            {
                return(null);
            }

            Inbox inbox = iCalMessage.FromInbox;

            /////
            // Ensure the inbox is set.
            /////
            if (inbox == null)
            {
                return(null);
            }

            /////
            // Create a new calendar.
            /////
            var reply = new iCalendar
            {
                Method = Methods.Reply
            };

            /////
            // Add the same time zones.
            /////
            foreach (ITimeZone timeZone in calendar.TimeZones)
            {
                reply.TimeZones.Add(timeZone);
            }

            /////
            // Add each event.
            /////
            foreach (IEvent existingCalendarEvent in calendar.Events)
            {
                var newCalendarEvent = new Event( );

                bool foundAttendee = false;

                /////
                // Search through the attendees looking for one that matches the inbox owner.
                /////
                foreach (IAttendee existingAttendee in existingCalendarEvent.Attendees)
                {
                    /////
                    // Regex out the email address from the Uri.
                    /////
                    string existingEmailAddress = GetEmailAddress(existingAttendee.Value.ToString( ));

                    /////
                    // If the address matches the inbox owner...
                    /////
                    if (existingEmailAddress != null && existingEmailAddress.ToLowerInvariant( ) == inbox.InboxEmailAddress.ToLowerInvariant( ))
                    {
                        /////
                        // Create a new attendee and set the participation status to accepted.
                        /////
                        var newAttendee = new Attendee(existingAttendee.Value)
                        {
                            ParticipationStatus = ParticipationStatus.Accepted
                        };

                        newCalendarEvent.Attendees.Add(newAttendee);

                        foundAttendee = true;
                        break;
                    }
                }

                if (foundAttendee)
                {
                    /////
                    // Copy the other event properties over.
                    /////
                    newCalendarEvent.Class        = existingCalendarEvent.Class;
                    newCalendarEvent.Comments     = existingCalendarEvent.Comments;
                    newCalendarEvent.DtEnd        = existingCalendarEvent.DtEnd;
                    newCalendarEvent.DtStamp      = existingCalendarEvent.DtStamp;
                    newCalendarEvent.Start        = existingCalendarEvent.Start;
                    newCalendarEvent.Location     = existingCalendarEvent.Location;
                    newCalendarEvent.Organizer    = existingCalendarEvent.Organizer;
                    newCalendarEvent.Priority     = existingCalendarEvent.Priority;
                    newCalendarEvent.Sequence     = existingCalendarEvent.Sequence;
                    newCalendarEvent.Status       = existingCalendarEvent.Status;
                    newCalendarEvent.Summary      = existingCalendarEvent.Summary;
                    newCalendarEvent.Transparency = existingCalendarEvent.Transparency;
                    newCalendarEvent.Uid          = existingCalendarEvent.Uid;

                    /////
                    // if there was an attendee found, add the event.
                    /////
                    reply.Events.Add(newCalendarEvent);
                }
            }

            return(reply);
        }
コード例 #4
0
        /// <summary>
        ///     Gets the Ical update.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="receivedICalEmailMessage">The received I cal email message.</param>
        /// <param name="iCal">The i cal.</param>
        /// <returns></returns>
        private static MailMessageFormatterResult GetICalUpdate(MailMessage message, ReceivedICalEmailMessage receivedICalEmailMessage, out string iCal)
        {
            iCal = null;

            if (message == null)
            {
                return(MailMessageFormatterResult.Skip);
            }

            try
            {
                var attachableItems = new List <AttachmentBase>( );

                attachableItems.AddRange(message.AlternateViews);
                attachableItems.AddRange(message.Attachments);

                /////
                // Locate a view that contains a calendar attachment.
                /////
                foreach (AttachmentBase attachment in attachableItems)
                {
                    if (attachment.ContentType.MediaType == "text/calendar")
                    {
                        /////
                        // Deserialize the iCalendar attachment.
                        /////
                        IICalendarCollection iCalendarCollection = iCalendar.LoadFromStream(attachment.ContentStream);

                        if (iCalendarCollection != null)
                        {
                            IICalendar calendar = iCalendarCollection.FirstOrDefault( );

                            if (calendar != null)
                            {
                                if (calendar.Method == Methods.Reply)
                                {
                                    IEvent calendarEvent = calendar.Events.FirstOrDefault( );

                                    if (calendarEvent != null && !string.IsNullOrEmpty(calendarEvent.Uid))
                                    {
                                        /////
                                        // Find all iCal UID containers that correlate to the received calendar events UID.
                                        /////
                                        IEnumerable <ICalUidContainer> iCalUidContainers = Entity.GetByField <ICalUidContainer>(calendarEvent.Uid, ICalUidContainer.ICalUid_Field);

                                        if (iCalUidContainers != null)
                                        {
                                            /////
                                            // Get the first iCal UID container.
                                            /////
                                            ICalUidContainer iCalUidContainer = iCalUidContainers.FirstOrDefault( );

                                            if (iCalUidContainer != null && iCalUidContainer.CalendarEventEmail != null)
                                            {
                                                /////
                                                // Get the original event email object that was used to calendar UID container.
                                                /////
                                                EventEmail eventEntity = iCalUidContainer.CalendarEventEmail;

                                                if (eventEntity != null)
                                                {
                                                    // ***************
                                                    // This needs to be fixed as part of dealing with replies from ical requests. The rel on a rel needs to be turned into something else.
                                                    // ***************
                                                    //IEntityRelationship<EventEmailAttendees, EmailContact> attendeeRelationshipInstance = FindAttendeeRelationshipInstance( eventEntity, message.From.Address.ToLowerInvariant( ) );

                                                    //if ( attendeeRelationshipInstance != null )
                                                    //{
                                                    //    Attendee attendee = FindICalAttendee( calendarEvent, message.From.Address.ToLowerInvariant( ) );

                                                    //    if ( attendee != null )
                                                    //    {
                                                    //        var eventEmailAttendees = attendeeRelationshipInstance.Instance.AsWritable<EventEmailAttendees>( );

                                                    //        switch ( attendee.ParticipationStatus )
                                                    //        {
                                                    //            case ParticipationStatus.Accepted:
                                                    //                eventEmailAttendees.AttendeeStatus_Enum = AttendeeStatusEnum_Enumeration.AttendeeStatusAccepted;
                                                    //                break;
                                                    //            case ParticipationStatus.Declined:
                                                    //                eventEmailAttendees.AttendeeStatus_Enum = AttendeeStatusEnum_Enumeration.AttendeeStatusDeclined;
                                                    //                break;
                                                    //            case ParticipationStatus.Delegated:
                                                    //                eventEmailAttendees.AttendeeStatus_Enum = AttendeeStatusEnum_Enumeration.AttendeeStatusDelegated;
                                                    //                break;
                                                    //            case ParticipationStatus.NeedsAction:
                                                    //                eventEmailAttendees.AttendeeStatus_Enum = AttendeeStatusEnum_Enumeration.AttendeeStatusNeedsAction;
                                                    //                break;
                                                    //            case ParticipationStatus.Tentative:
                                                    //                eventEmailAttendees.AttendeeStatus_Enum = AttendeeStatusEnum_Enumeration.AttendeeStatusTentative;
                                                    //                break;
                                                    //        }

                                                    //        eventEmailAttendees.Save( );
                                                    //    }
                                                    //}

                                                    //*************

                                                    receivedICalEmailMessage.CreatedEventEmail = eventEntity;

                                                    /////
                                                    // Save the message since the process inbox action will discard it.
                                                    /////
                                                    receivedICalEmailMessage.Save( );
                                                }
                                            }
                                        }
                                    }

                                    return(MailMessageFormatterResult.Reject);
                                }

                                /////
                                // Serialize the iCalendar to a string for storage.
                                /////
                                var serializer = new iCalendarSerializer( );

                                iCal = serializer.SerializeToString(calendar);

                                return(MailMessageFormatterResult.Ok);
                            }
                        }

                        break;
                    }
                }
            }
            catch (Exception exc)
            {
                EventLog.Application.WriteError("Failed to process email iCal attachment. " + exc);

                return(MailMessageFormatterResult.Error);
            }

            return(MailMessageFormatterResult.Skip);
        }