Public Access
100 lines
3.3 KiB
C#
100 lines
3.3 KiB
C#
#if WINDOWS
|
|
using MeetingAssistant.Calendar;
|
|
|
|
namespace MeetingAssistant.MeetingNotes;
|
|
|
|
internal static class OutlookClassicAppointmentMetadata
|
|
{
|
|
public static MeetingMetadata CreateMetadata(object appointment, DateTime end)
|
|
{
|
|
return CalendarAppointmentMetadata.Create(
|
|
Convert.ToString(OutlookClassicCom.GetProperty(appointment, "Subject")),
|
|
ReadAttendees(appointment),
|
|
Convert.ToString(OutlookClassicCom.GetProperty(appointment, "Body")),
|
|
OutlookClassicCom.ToLocalOffset(end));
|
|
}
|
|
|
|
public static string ReadSubject(object appointment)
|
|
{
|
|
return CalendarAppointmentMetadata.ReadSubject(
|
|
Convert.ToString(OutlookClassicCom.GetProperty(appointment, "Subject")));
|
|
}
|
|
|
|
public static bool IsTeamsAppointment(object appointment)
|
|
{
|
|
var subject = Convert.ToString(OutlookClassicCom.GetProperty(appointment, "Subject")) ?? "";
|
|
var location = Convert.ToString(OutlookClassicCom.GetProperty(appointment, "Location")) ?? "";
|
|
var body = Convert.ToString(OutlookClassicCom.GetProperty(appointment, "Body")) ?? "";
|
|
return CalendarAppointmentMetadata.IsTeamsAppointment(subject, location, body);
|
|
}
|
|
|
|
public static string ExtractAgenda(string body)
|
|
{
|
|
return CalendarAppointmentMetadata.ExtractAgenda(body);
|
|
}
|
|
|
|
public static IReadOnlyList<string> ReadAttendees(object appointment)
|
|
{
|
|
var attendees = new List<string>();
|
|
var organizer = Convert.ToString(OutlookClassicCom.GetProperty(appointment, "Organizer"));
|
|
if (!string.IsNullOrWhiteSpace(organizer))
|
|
{
|
|
attendees.Add(organizer.Trim());
|
|
}
|
|
|
|
object? recipients = null;
|
|
try
|
|
{
|
|
recipients = OutlookClassicCom.GetProperty(appointment, "Recipients");
|
|
var count = Convert.ToInt32(OutlookClassicCom.GetProperty(recipients!, "Count"));
|
|
for (var index = 1; index <= count; index++)
|
|
{
|
|
object? recipient = null;
|
|
try
|
|
{
|
|
recipient = OutlookClassicCom.Invoke(recipients!, "Item", index);
|
|
var formatted = FormatRecipient(recipient!);
|
|
if (!string.IsNullOrWhiteSpace(formatted))
|
|
{
|
|
attendees.Add(formatted);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
OutlookClassicCom.ReleaseComObject(recipient);
|
|
}
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
OutlookClassicCom.ReleaseComObject(recipients);
|
|
}
|
|
|
|
return NormalizeAttendees(attendees);
|
|
}
|
|
|
|
public static IReadOnlyList<string> NormalizeAttendees(IEnumerable<string> attendees)
|
|
{
|
|
return CalendarAppointmentMetadata.NormalizeAttendees(attendees);
|
|
}
|
|
|
|
private static string FormatRecipient(object recipient)
|
|
{
|
|
var name = Convert.ToString(OutlookClassicCom.GetProperty(recipient, "Name"))?.Trim() ?? "";
|
|
var email = Convert.ToString(OutlookClassicCom.GetProperty(recipient, "Address"))?.Trim() ?? "";
|
|
if (string.IsNullOrWhiteSpace(name))
|
|
{
|
|
return email;
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(email) ||
|
|
email.Contains('/'))
|
|
{
|
|
return name;
|
|
}
|
|
|
|
return $"{name} <{email}>";
|
|
}
|
|
}
|
|
#endif
|