Correct time for uploading emails

My app parses emails into a database and it can re-upload the emails into the account. But I’m not getting the correct time back.

Original email in Mail with time 12:04:

Email in my app with time 12:04:

But when I upload the email I get a difference of 2 hours:

The time is now 14:04 and not 12:04.

The code is quite simple:

dim d as new Chilkat.CkDateTime
dim time as String = Str(maildate.Year) + "-" + Str(maildate.Month) + "-" + Str(MailDate.Day) + "T" + str(MailDate.Hour) + ":" + str(MailDate.Minute) + ":" + str(MailDate.Second) + "Z"
call d.SetFromTimestamp(time)
'YYYY-MM-DDThh:mm:ssTZD
dim UploadTask as Chilkat.Task = CkoImap.AppendMimeWithDateStrAsync(theMailbox, email.GetMime, d.GetAsRfc822(false))
call UploadTask.Run

What do I need to do to get the correct time?

IT’s seem to be a TimeZone problem.
Do you play with the GMTOffset date property ? When saving or uploading don’t you have to set the right GMTOffset that I think is +2 in your country ?

That’s a good idea. However, how do I get the GMTOffset for past dates?

You must read the end of the DateTime.
If the DateTime string received ends with “+0600”, the GMTOffset is 6
In order to set the right date, you must do something like that :
dim dt as new Date
dim myGMTOffset As Double
myGMTOffset = dt.GMTOffset
dt.GMTOffset = 6
set the time
set now your GMTOffset : dt.GMTOffset = myGMTOffset

Can you go to the original email, then View - Message - Raw Source and post all Received: and Date: that you see, then do the same for the uploaded email?

What date do you use when you parse the emails? I don’t see TimeZone on the posted code.

Do you always get 2 hour difference or that changes sometimes?

Here are the full headers of

Original email:

Return-Path: bounce+5f1231.5e9113-mail=beatrixwillius.de@cloud.acronis.com
X-Original-To: mail@beatrixwillius.de
Delivered-To: mail@beatrixwillius.de
Received: from m229-208.mailgun.net (m229-208.mailgun.net [159.135.229.208])
by d167.x-mailer.de (Postfix) with ESMTPS id 0CA993B5CC1
for mail@beatrixwillius.de; Mon, 12 Apr 2021 12:04:32 +0200 (CEST)
DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=cloud.acronis.com; q=dns/txt;
s=mailo; t=1618221873; h=Message-ID: Sender: From: Date: To: Subject:
MIME-Version: Content-Type;
bh=aA5k4wHkdnFZmxUY/SBfQtjSbrFUvj64+BJOHgcvM/E=; b=baSlyjxp8mhDdBHev70Xvwx3Wv5zwT53f5bMOdDzBmzv4TJ//OS4pKrYcEMKyMkt6kZmU2y+
dqwUQOJEFUlxJrQb4i4buYw4QNt+HR2a8wfRJw1vIVDcziVwiUeKi2skg4aa4J9UAzkCLVkb
+iUlf/AQI4wHb6PP9Bw9FEeD5uk=
X-Mailgun-Sending-Ip: 159.135.229.208
X-Mailgun-Sid: WyJhNmNkYiIsICJtYWlsQGJlYXRyaXh3aWxsaXVzLmRlIiwgIjVlOTExMyJd
Received: from eu4-cloud.acronis.com ( [45.11.129.1]) by
smtp-out-n02.prod.us-west-2.postgun.com with SMTP id
60741b2d8807bcde1d4f7801; Mon, 12 Apr 2021 10:04:29 GMT
Content-Type: multipart/related;
boundary=“===============1445196352724677297==”
MIME-Version: 1.0
Subject: Trixis iMac - Backup erfolgreich abgeschlossen - beatrixwillius 1
To: mail@beatrixwillius.de
Original-Message-ID: acb39dc2-2aeb-462e-8787-fbda9d317078
Date: Mon, 12 Apr 2021 10:04:24 -0000
X-Sending-Expiration: Sat, 17 Apr 2021 10:04:24 -0000
From: noreply-abc@cloud.acronis.com
Sender: noreply-abc@cloud.acronis.com
Message-ID: zEzq3P4ugvdNsx35UYim3d.0@eu4-cloud.acronis.com

Uploaded email:

Return-Path: bounce+5f1231.5e9113-mail=beatrixwillius.de@cloud.acronis.com
X-Original-To: mail@beatrixwillius.de
Delivered-To: mail@beatrixwillius.de
Received: from m229-208.mailgun.net (m229-208.mailgun.net [159.135.229.208])
by d167.x-mailer.de (Postfix) with ESMTPS id 0CA993B5CC1
for mail@beatrixwillius.de; Mon, 12 Apr 2021 12:04:32 +0200 (CEST)
DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=cloud.acronis.com;
q=dns/txt; s=mailo; t=1618221873; h=Message-ID: Sender: From: Date: To:
Subject: MIME-Version: Content-Type; bh=aA5k4wHkdnFZmxUY/SBfQtjSbrFUvj64+BJOHgcvM/E=;
b=baSlyjxp8mhDdBHev70Xvwx3Wv5zwT53f5bMOdDzBmzv4TJ//OS4pKrYcEMKyMkt6kZmU2y+
dqwUQOJEFUlxJrQb4i4buYw4QNt+HR2a8wfRJw1vIVDcziVwiUeKi2skg4aa4J9UAzkCLVkb
+iUlf/AQI4wHb6PP9Bw9FEeD5uk=
X-Mailgun-Sending-Ip: 159.135.229.208
X-Mailgun-Sid: WyJhNmNkYiIsICJtYWlsQGJlYXRyaXh3aWxsaXVzLmRlIiwgIjVlOTExMyJd
Received: from eu4-cloud.acronis.com ( [45.11.129.1]) by smtp-out-n02.prod.us-west-2.postgun.com with SMTP id 60741b2d8807bcde1d4f7801; Mon, 12 Apr 2021 10:04:29 GMT
Content-Type: multipart/related; boundary=“===============1445196352724677297==”
MIME-Version: 1.0
Subject: Trixis iMac - Backup erfolgreich abgeschlossen - beatrixwillius 1
To: mail@beatrixwillius.de
Original-Message-ID: acb39dc2-2aeb-462e-8787-fbda9d317078
Date: Mon, 12 Apr 2021 10:04:24 -0000
X-Sending-Expiration: Sat, 17 Apr 2021 10:04:24 -0000
From: noreply-abc@cloud.acronis.com
Sender: noreply-abc@cloud.acronis.com
Message-ID: zEzq3P4ugvdNsx35UYim3d.0@eu4-cloud.acronis.com

I don’t see a difference between the headers.

Parsing the date is much too complex to post here. Different email clients use slightly different dates. I modelled my code after Mail which uses the first date in the received part of the header.

I have a report from a user who complained about getting a 7 hour difference after uploading the email. When not in daylight savings time I get a one hour difference. So it must be time zone related.

I don’t see a difference here either. I wonder if has to do with when the re-upload occurs, as the original date and time has long passed?

Who knows what email clients do, especially Mail.

Result now seems correct:

Code:

Private Function makeUpdateDate(theDate as Date) as Date
  
  if theDate = Nil then Return Nil
  
  dim CheckDate as DateTime = theDate
  dim theTimeZone as TimeZone = CheckDate.Timezone
  
  theDate.TotalSeconds = theDate.TotalSeconds - theTimeZone.SecondsFromGMT
  
  Return theDate

End Function

Thank you Beatrix. Is weird that the received: and date: are the same in original and uploaded, I expected a difference because I played with the date on an email received and using mail.

What I did is:

  • download the email to the computer
  • open it in a text editor
  • change the time on each received: date I could find (make it unique to know which one Mail used to display the date and time
  • change received: to received2: so next load the mail program will not use that date and time

but it looks like now you are getting the correct date.

I booted my Mac on a just downloaded Live DVD and noticed the date with -2 hours… ;-:slight_smile:

I do not installed it, just booted.