Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 10 commits
  • 5 files changed
  • 0 commit comments
  • 2 contributors
Commits on Dec 21, 2011
Ryan Boggs Begin work on adding tests for the newly updated MailTask. 2224ada
Commits on Dec 23, 2011
Ryan Boggs Adding netDumbster.dll for MailTask tests. Still a work in progress. c0521f9
Commits on Jan 01, 2012
Ryan Boggs Merge remote-tracking branch 'upstream/master' into mailtaskupdate e8023bb
Commits on Jan 02, 2012
Ryan Boggs Created new unit tests for the newly modified Mail task. In the proce…
…ss, the old unit tests were removed as they were all marked as broken since the NAnt 0.90 release (if not, before).
7721bb7
Ryan Boggs Got the new mail task tests working. All but three are passing at the…
… moment.
c2796a6
Commits on Jan 03, 2012
Ryan Boggs Adjusted the email validation process of the MailTask to catch possib…
…le mistakes rather than simply passing them on.

All new 40+ unit tests for MailTask now pass on both .NET 2.0/4.0.
785329c
Commits on Jan 04, 2012
Ryan Boggs Fixed an issue with MailTask when it is setup with default credential…
…s when running on Mono.
7e6dad0
Ryan Boggs Merge remote-tracking branch 'origin/mailtaskupdate' into mailtaskupdate dcb2c28
Ryan Boggs Add note regarding UseDefaultCredentials update in MailTask. 8bdd188
Commits on Jan 19, 2012
@dguder dguder Merge pull request #19 from rmboggs/mailtaskupdate
Mailtaskupdate - Minor adjustments and unit tests
2f1be53
View
BIN lib/common/neutral/netDumbster.dll
Binary file not shown.
View
93 src/NAnt.Core/Tasks/MailTask.cs
@@ -468,7 +468,19 @@ public MailFormat Format
}
else
{
- smtp.UseDefaultCredentials = true;
+ // Mono does not implement the UseDefaultCredentials
+ // property in the SmtpClient class. So only set the
+ // property when NAnt is run on .NET. Otherwise,
+ // use an emtpy NetworkCredential object as the
+ // SmtpClient credentials.
+ if (PlatformHelper.IsMono)
+ {
+ smtp.Credentials = new NetworkCredential();
+ }
+ else
+ {
+ smtp.UseDefaultCredentials = true;
+ }
}
// Set the ssl and the port information.
@@ -520,8 +532,11 @@ public MailFormat Format
/// The content of the specified file.
/// </returns>
private string ReadFile(string filename) {
- using (StreamReader reader = new StreamReader(File.OpenRead(filename))) {
- return reader.ReadToEnd();
+ using (StreamReader reader = new StreamReader(File.OpenRead(filename)))
+ {
+ string result = reader.ReadToEnd();
+ reader.Close();
+ return result;
}
}
@@ -615,6 +630,10 @@ private MailAddress ConvertStringToMailAddress(string address)
// normal string. Makes validation easier.
string plainAddress = UnescapeXmlCodes(address);
+ // Local vars to temporarily hold names and email addresses
+ string resultingName = null;
+ string resultingEmail = null;
+
// String array containing all of the regex strings used to
// locate the email address in the parameter string.
string[] validators = new string[]
@@ -629,10 +648,7 @@ private MailAddress ConvertStringToMailAddress(string address)
@"^\((?<fullname>.+)\)\s(?<email>[^<>\(\)\s]+@[^<>\(\)\s]+\.[^<>\(\)\s]+)$",
// Format: address@abcxyz.com (Full Name)
- @"^(?<email>[^<>\(\)\s]+@[^<>\(\)\s]+\.[^\s]+)\s\((?<fullname>.+)\)$",
-
- // Format: address@abcxyz.com
- @"(?<email>[^<>\(\)\s]+@[^<>\(\)\s]+\.[^<>\(\)\s]+)"
+ @"^(?<email>[^<>\(\)\s]+@[^<>\(\)\s]+\.[^\s]+)\s\((?<fullname>.+)\)$"
};
// Loop through each regex string to find the one that the
@@ -645,29 +661,58 @@ private MailAddress ConvertStringToMailAddress(string address)
Regex currentRegex = new Regex(reg);
Match email = currentRegex.Match(plainAddress);
- // If the match is considered successful, return
- // a new MailAddress object. If a name was
- // paired with an email address in the parameter,
- // add it to the MailAddress object that is returned.
+ // If the match is considered successful, load
+ // the temp string vars with the found email/fullname
+ // information to use when creating a new MailAddress
+ // object. Then break from the loop.
if (email.Success)
{
- if (email.Groups["fullname"].Success)
- {
- return new MailAddress(
- email.Groups["email"].Value.Trim(),
- email.Groups["fullname"].Value.Trim());
- }
-
- return new MailAddress(email.Groups["email"].Value.Trim());
+ resultingEmail = email.Groups["email"].Value.Trim();
+ resultingName = email.Groups["fullname"].Value.Trim();
+ break;
}
}
- // If none of the regex strings matches the address parameter,
+ try
+ {
+ // Setup a new MailAddress to return.
+ MailAddress result;
+
+ // If both the temp name and email string vars contain values, initialize
+ // the result MailAddress var with both values.
+ if (!String.IsNullOrEmpty(resultingName) && !String.IsNullOrEmpty(resultingEmail))
+ {
+ result = new MailAddress(resultingEmail, resultingName);
+ }
+ // If only the temp email string var contains a value, initialize
+ // the result MailAddress var with just that value
+ else if (!String.IsNullOrEmpty(resultingEmail))
+ {
+ result = new MailAddress(resultingEmail);
+ }
+ // Otherwise, try initializing the result MailAddress var with the original
+ // address that was passed to the method.
+ else
+ {
+ result = new MailAddress(plainAddress);
+ }
+ // Return the result.
+ return result;
+ }
+ // If the MailAddress var throws a Format exception because of a bad email address,
// throw a build exception.
- throw new BuildException(
- String.Format(CultureInfo.InvariantCulture,
- "{0} is not a recognized email address",
- address));
+ catch (FormatException)
+ {
+ throw new BuildException(
+ String.Format(CultureInfo.InvariantCulture,
+ "{0} is not a recognized email address",
+ plainAddress));
+ }
+ // Rethrow any other exceptions.
+ catch (Exception)
+ {
+ throw;
+ }
}
/// <summary>
View
1 tests/NAnt.Core/NAnt.Core.build
@@ -23,6 +23,7 @@
<references>
<include name="${build.dir}/bin/NAnt.Core.dll" />
<include name="${nant::scan-probing-paths('nunit.framework.dll')}" />
+ <include name="${nant::scan-probing-paths('netDumbster.dll')}" />
</references>
<resources failonempty="true" basedir="Resources" dynamicprefix="true" prefix="XML:">
<include name="**/*.xml"/>
View
1,911 tests/NAnt.Core/Tasks/MailTaskTest.cs
1,618 additions, 293 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
5 tests/NAnt.Tests.csproj
@@ -58,6 +58,9 @@
<Reference Include="nunit.framework">
<HintPath>..\lib\net\1.0\nunit.framework.dll</HintPath>
</Reference>
+ <Reference Include="netDumbster">
+ <HintPath>..\lib\common\neutral\netDumbster.dll</HintPath>
+ </Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\src\CommonAssemblyInfo.cs">
@@ -110,7 +113,7 @@
<Compile Include="NAnt.Core\Tasks\IncludeTaskTest.cs" />
<Compile Include="NAnt.Core\Tasks\LoadTasksTest.cs" />
<Compile Include="NAnt.Core\Tasks\LoopTest.cs" />
- <None Include="NAnt.Core\Tasks\MailTaskTest.cs" />
+ <Compile Include="NAnt.Core\Tasks\MailTaskTest.cs" />
<Compile Include="NAnt.Core\Tasks\MkDirTest.cs" />
<Compile Include="NAnt.Core\Tasks\MoveTest.cs" />
<Compile Include="NAnt.Core\Tasks\NAntTaskTest.cs" />

No commit comments for this range

Something went wrong with that request. Please try again.