Some threading stuff.
This commit is contained in:
@@ -69,7 +69,7 @@ public static class OutlookIntegratorExtensions
|
|||||||
return mailCopy;
|
return mailCopy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Message AsOutlookMessage(this MimeMessage mime, bool includeInternetHeaders)
|
public static Message AsOutlookMessage(this MimeMessage mime, bool includeInternetHeaders, string conversationId = null)
|
||||||
{
|
{
|
||||||
var fromAddress = GetRecipients(mime.From).ElementAt(0);
|
var fromAddress = GetRecipients(mime.From).ElementAt(0);
|
||||||
var toAddresses = GetRecipients(mime.To).ToList();
|
var toAddresses = GetRecipients(mime.To).ToList();
|
||||||
@@ -93,6 +93,12 @@ public static class OutlookIntegratorExtensions
|
|||||||
Attachments = []
|
Attachments = []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Set ConversationId if provided to maintain threading
|
||||||
|
if (!string.IsNullOrEmpty(conversationId))
|
||||||
|
{
|
||||||
|
message.ConversationId = conversationId;
|
||||||
|
}
|
||||||
|
|
||||||
// Headers are only included when creating the draft.
|
// Headers are only included when creating the draft.
|
||||||
// When sending, they are not included. Graph will throw an error.
|
// When sending, they are not included. Graph will throw an error.
|
||||||
|
|
||||||
|
|||||||
@@ -1231,7 +1231,9 @@ public class OutlookSynchronizer : WinoSynchronizer<RequestInformation, Message,
|
|||||||
// Alias support is lacking with direct MIMEs.
|
// Alias support is lacking with direct MIMEs.
|
||||||
// Therefore we convert the MIME message to Outlook message and use proper APIs.
|
// Therefore we convert the MIME message to Outlook message and use proper APIs.
|
||||||
|
|
||||||
var outlookMessage = mimeMessage.AsOutlookMessage(false);
|
// Pass the ConversationId (ThreadId) to maintain threading for replies/forwards
|
||||||
|
var conversationId = sendDraftPreparationRequest.MailItem.ThreadId;
|
||||||
|
var outlookMessage = mimeMessage.AsOutlookMessage(false, conversationId);
|
||||||
|
|
||||||
// Create attachment requests.
|
// Create attachment requests.
|
||||||
// TODO: We need to support large file attachments with sessioned upload at some point.
|
// TODO: We need to support large file attachments with sessioned upload at some point.
|
||||||
|
|||||||
@@ -962,6 +962,7 @@ public class WinoMailCollection : ObservableRecipient, IRecipient<SelectedItemsC
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
Messenger.Unregister<SelectedItemsChangedMessage>(this);
|
||||||
Messenger.Register<SelectedItemsChangedMessage>(this);
|
Messenger.Register<SelectedItemsChangedMessage>(this);
|
||||||
Messenger.Send(new SelectedItemsChangedMessage());
|
Messenger.Send(new SelectedItemsChangedMessage());
|
||||||
|
|
||||||
|
|||||||
@@ -936,12 +936,43 @@ public class MailService : BaseDatabaseService, IMailService
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Manage "ThreadId-ConversationId"
|
// Manage "ThreadId-ConversationId"
|
||||||
|
// CRITICAL: In-Reply-To and References headers are essential for threading
|
||||||
|
// They must reference the original message's Message-ID from the MIME headers
|
||||||
if (!string.IsNullOrEmpty(referenceMessage.MessageId))
|
if (!string.IsNullOrEmpty(referenceMessage.MessageId))
|
||||||
{
|
{
|
||||||
message.InReplyTo = referenceMessage.MessageId;
|
message.InReplyTo = referenceMessage.MessageId;
|
||||||
|
|
||||||
|
// Add all previous References first
|
||||||
|
if (referenceMessage.References != null && referenceMessage.References.Count > 0)
|
||||||
|
{
|
||||||
message.References.AddRange(referenceMessage.References);
|
message.References.AddRange(referenceMessage.References);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then add the message we're replying to
|
||||||
message.References.Add(referenceMessage.MessageId);
|
message.References.Add(referenceMessage.MessageId);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// WARNING: Reference message has no Message-ID!
|
||||||
|
// This will break threading. Try to use the MessageId from MailCopy if available.
|
||||||
|
var referenceMailCopy = draftCreationOptions.ReferencedMessage.MailCopy;
|
||||||
|
if (referenceMailCopy != null && !string.IsNullOrEmpty(referenceMailCopy.MessageId))
|
||||||
|
{
|
||||||
|
message.InReplyTo = referenceMailCopy.MessageId;
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(referenceMailCopy.References))
|
||||||
|
{
|
||||||
|
// Parse the References string and add them
|
||||||
|
var references = referenceMailCopy.References.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
foreach (var reference in references)
|
||||||
|
{
|
||||||
|
message.References.Add(reference.Trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message.References.Add(referenceMailCopy.MessageId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
message.Headers.Add("Thread-Topic", referenceMessage.Subject);
|
message.Headers.Add("Thread-Topic", referenceMessage.Subject);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user