Skip to content

Commit

Permalink
Make sure to use the InvariantCulture when converting port values to …
Browse files Browse the repository at this point in the history
…a string

May fix issue #1040
  • Loading branch information
jstedfast committed Jun 18, 2020
1 parent 03d8c31 commit d7779d2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
11 changes: 6 additions & 5 deletions MailKit/Net/Imap/ImapClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using System.Threading;
using System.Net.Sockets;
using System.Net.Security;
using System.Globalization;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
Expand Down Expand Up @@ -787,7 +788,7 @@ string GetSessionIdentifier (string userName)
{
var uri = engine.Uri;

return string.Format ("{0}://{1}@{2}:{3}", uri.Scheme, EscapeUserName (userName), uri.Host, uri.Port);
return string.Format (CultureInfo.InvariantCulture, "{0}://{1}@{2}:{3}", uri.Scheme, EscapeUserName (userName), uri.Host, uri.Port);
}

async Task OnAuthenticatedAsync (string message, bool doAsync, CancellationToken cancellationToken)
Expand Down Expand Up @@ -1174,19 +1175,19 @@ internal static void ComputeDefaultValues (string host, ref int port, ref Secure

switch (options) {
case SecureSocketOptions.StartTlsWhenAvailable:
uri = new Uri ("imap://" + host + ":" + port + "/?starttls=when-available");
uri = new Uri (string.Format (CultureInfo.InvariantCulture, "imap://{0}:{1}/?starttls=when-available", host, port));
starttls = true;
break;
case SecureSocketOptions.StartTls:
uri = new Uri ("imap://" + host + ":" + port + "/?starttls=always");
uri = new Uri (string.Format (CultureInfo.InvariantCulture, "imap://{0}:{1}/?starttls=always", host, port));
starttls = true;
break;
case SecureSocketOptions.SslOnConnect:
uri = new Uri ("imaps://" + host + ":" + port);
uri = new Uri (string.Format (CultureInfo.InvariantCulture, "imaps://{0}:{1}", host, port));
starttls = false;
break;
default:
uri = new Uri ("imap://" + host + ":" + port);
uri = new Uri (string.Format (CultureInfo.InvariantCulture, "imap://{0}:{1}", host, port));
starttls = false;
break;
}
Expand Down
8 changes: 4 additions & 4 deletions MailKit/Net/Pop3/Pop3Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -836,19 +836,19 @@ internal static void ComputeDefaultValues (string host, ref int port, ref Secure

switch (options) {
case SecureSocketOptions.StartTlsWhenAvailable:
uri = new Uri ("pop://" + host + ":" + port + "/?starttls=when-available");
uri = new Uri (string.Format (CultureInfo.InvariantCulture, "pop://{0}:{1}/?starttls=when-available", host, port));
starttls = true;
break;
case SecureSocketOptions.StartTls:
uri = new Uri ("pop://" + host + ":" + port + "/?starttls=always");
uri = new Uri (string.Format (CultureInfo.InvariantCulture, "pop://{0}:{1}/?starttls=always", host, port));
starttls = true;
break;
case SecureSocketOptions.SslOnConnect:
uri = new Uri ("pops://" + host + ":" + port);
uri = new Uri (string.Format (CultureInfo.InvariantCulture, "pops://{0}:{1}", host, port));
starttls = false;
break;
default:
uri = new Uri ("pop://" + host + ":" + port);
uri = new Uri (string.Format (CultureInfo.InvariantCulture, "pop://{0}:{1}", host, port));
starttls = false;
break;
}
Expand Down
8 changes: 4 additions & 4 deletions MailKit/Net/Smtp/SmtpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -960,19 +960,19 @@ internal static void ComputeDefaultValues (string host, ref int port, ref Secure

switch (options) {
case SecureSocketOptions.StartTlsWhenAvailable:
uri = new Uri ("smtp://" + host + ":" + port + "/?starttls=when-available");
uri = new Uri (string.Format (CultureInfo.InvariantCulture, "smtp://{0}:{1}/?starttls=when-available", host, port));
starttls = true;
break;
case SecureSocketOptions.StartTls:
uri = new Uri ("smtp://" + host + ":" + port + "/?starttls=always");
uri = new Uri (string.Format (CultureInfo.InvariantCulture, "smtp://{0}:{1}/?starttls=always", host, port));
starttls = true;
break;
case SecureSocketOptions.SslOnConnect:
uri = new Uri ("smtps://" + host + ":" + port);
uri = new Uri (string.Format (CultureInfo.InvariantCulture, "smtps://{0}:{1}", host, port));
starttls = false;
break;
default:
uri = new Uri ("smtp://" + host + ":" + port);
uri = new Uri (string.Format (CultureInfo.InvariantCulture, "smtp://{0}:{1}", host, port));
starttls = false;
break;
}
Expand Down

0 comments on commit d7779d2

Please sign in to comment.