diff --git a/dotnet/src/dotnetframework/GxMail/MailMessage.cs b/dotnet/src/dotnetframework/GxMail/MailMessage.cs index a7b24fa15..8ed31895f 100644 --- a/dotnet/src/dotnetframework/GxMail/MailMessage.cs +++ b/dotnet/src/dotnetframework/GxMail/MailMessage.cs @@ -624,68 +624,71 @@ public DateTime GetDateReceived() */ internal static DateTime GetMessageDate(string stringDate) { - DateTime messageTime; + DateTime messageTime = DateTime.Now; try { - bool oldDateSpec = (stringDate.IndexOf("/") != -1); - bool hasStrDay = (stringDate.IndexOf(",") > 0); //StrDay is not empty - string dateStr = RemoveQuotes(stringDate.Replace("/", " ").Replace(",", "").Trim()); - string[] dateParts = dateStr.Split(" ".ToCharArray()); + if (!string.IsNullOrEmpty(stringDate)) + { + bool oldDateSpec = (stringDate.IndexOf("/") != -1); + bool hasStrDay = (stringDate.IndexOf(",") > 0); //StrDay is not empty + string dateStr = RemoveQuotes(stringDate.Replace("/", " ").Replace(",", "").Trim()); + string[] dateParts = dateStr.Split(" ".ToCharArray()); - int i = hasStrDay?0:-1; - if (!IsNumber(dateParts[i+1])) - i = i + 1; + int i = hasStrDay ? 0 : -1; + if (!IsNumber(dateParts[i + 1])) + i = i + 1; - if (oldDateSpec) - { - string[] tmpDateParts = new string[dateParts.Length]; - for(int j=0; j 1) - mm = int.Parse(tmpTime[1]); + if (tmpTime.Length > 1) + mm = int.Parse(tmpTime[1]); - if (tmpTime.Length > 2) - ss = int.Parse(tmpTime[2]); + if (tmpTime.Length > 2) + ss = int.Parse(tmpTime[2]); - string timeZoneOffset = string.Empty; - if (dateParts.Length > i + 5) - { - timeZoneOffset = dateParts[i + 5]; - } + string timeZoneOffset = string.Empty; + if (dateParts.Length > i + 5) + { + timeZoneOffset = dateParts[i + 5]; + } - messageTime = DateTimeUtil.DateTimeWithTimeZoneToUTC(year, month, day, hr, mm, ss, timeZoneOffset); - if (GeneXus.Application.GxContext.Current != null) - { - messageTime = DateTimeUtil.FromTimeZone(messageTime, "Etc/UTC", GeneXus.Application.GxContext.Current); - } - else - { - messageTime = messageTime.ToLocalTime(); - } + messageTime = DateTimeUtil.DateTimeWithTimeZoneToUTC(year, month, day, hr, mm, ss, timeZoneOffset); + if (GeneXus.Application.GxContext.Current != null) + { + messageTime = DateTimeUtil.FromTimeZone(messageTime, "Etc/UTC", GeneXus.Application.GxContext.Current); + } + else + { + messageTime = messageTime.ToLocalTime(); + } + } } - catch + catch(Exception ex) { - messageTime = DateTime.Now; + GXLogging.Warn(log, $"Date {stringDate} can't be parsed", ex); } return messageTime; } diff --git a/dotnet/src/dotnetframework/GxMail/Pop3MailKit.cs b/dotnet/src/dotnetframework/GxMail/Pop3MailKit.cs index 625cfd3be..ce6e9292a 100644 --- a/dotnet/src/dotnetframework/GxMail/Pop3MailKit.cs +++ b/dotnet/src/dotnetframework/GxMail/Pop3MailKit.cs @@ -197,7 +197,7 @@ private string GetHeaderFromMimeMessage(MimeMessage msg, string headerValue) private void ProcessMailAttachments(GXMailMessage gxmessage, IEnumerable attachs) { - if (attachs == null || attachs.GetEnumerator().MoveNext()) // Si MoveNext es false significa que el attach viene vacio + if (attachs == null) return; if (DownloadAttachments) @@ -229,7 +229,7 @@ private void ProcessMailAttachments(GXMailMessage gxmessage, IEnumerable