Skip to content

Commit

Permalink
Add code to detect the timezone where the message was created
Browse files Browse the repository at this point in the history
  • Loading branch information
Kees van Spelde committed May 26, 2024
1 parent 895d851 commit 517b495
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions MsgReaderCore/Outlook/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ public class Message : Storage
/// </summary>
private DateTime? _sentOn;

/// <summary>
/// <see cref="TimeZone"/>
/// </summary>
private TimeZoneInfo _timeZone;

/// <summary>
/// Contains the date/time in UTC format when the <see cref="Storage.Message" /> object has been received,
/// null when not available
Expand Down Expand Up @@ -924,6 +929,31 @@ public DateTime? SentOn
}
}


/// <summary>
/// Returns the <see cref="TimeZoneInfo"/> in which this message was created. This property is only filled when<br/>
/// the e-mail has been sent accross the internet and the <see cref="Headers"/> property is filled.<br/>
/// When the <see cref="Headers"/> property is not filled, this property will return <c>null</c>
/// </summary>
public TimeZoneInfo TimeZone
{
get
{
if (_timeZone != null) return _timeZone;

var date = Headers?.RawHeaders["Date"];
if (string.IsNullOrWhiteSpace(date)) return null;

if (!DateTimeOffset.TryParse(date, out var dateTimeOffset)) return null;

_timeZone = dateTimeOffset.Offset == TimeSpan.Zero
? TimeZoneInfo.Utc
: TimeZoneInfo.FindSystemTimeZoneById(TimeZoneInfo.GetSystemTimeZones().First(timeZone => timeZone.BaseUtcOffset == dateTimeOffset.Offset).Id);

return _timeZone;
}
}

/// <summary>
/// PR_MESSAGE_DELIVERY_TIME is the time that the message was delivered to the store and
/// PR_CLIENT_SUBMIT_TIME is the time when the message was sent by the client (Outlook) to the server.
Expand Down

0 comments on commit 517b495

Please sign in to comment.