Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,105 @@
//
// System.Web.Mail.Base64AttachmentEncoder.cs
//
// Author(s):
// Per Arneng <pt99par@student.bth.se>
//
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;
namespace System.Web.Mail {
// a class that handles Base64 encoding for attachments
internal class Base64AttachmentEncoder : IAttachmentEncoder {
// reads bytes from a stream and writes the encoded
// as base64 encoded characters. ( 60 chars on each row)
public void EncodeStream( Stream ins , Stream outs ) {
if( ( ins == null ) || ( outs == null ) )
throw new ArgumentNullException( "The input and output streams may not " +
"be null.");
ICryptoTransform base64 = new ToBase64Transform();
// the buffers
byte[] plainText = new byte[ base64.InputBlockSize ];
byte[] cipherText = new byte[ base64.OutputBlockSize ];
int readLength = 0;
int count = 0;
byte[] newln = new byte[] { 13 , 10 }; //CR LF with mail
// read through the stream until there
// are no more bytes left
while( true ) {
// read some bytes
readLength = ins.Read( plainText , 0 , plainText.Length );
// break when there is no more data
if( readLength < 1 ) break;
// transfrom and write the blocks. If the block size
// is less than the InputBlockSize then write the final block
if( readLength == plainText.Length ) {
base64.TransformBlock( plainText , 0 ,
plainText.Length ,
cipherText , 0 );
// write the data
outs.Write( cipherText , 0 , cipherText.Length );
// do this to output lines that
// are 60 chars long
count += cipherText.Length;
if( count == 60 ) {
outs.Write( newln , 0 , newln.Length );
count = 0;
}
} else {
// convert the final blocks of bytes and write them
cipherText = base64.TransformFinalBlock( plainText , 0 , readLength );
outs.Write( cipherText , 0 , cipherText.Length );
}
}
outs.Write( newln , 0 , newln.Length );
}
}
}

View File

@@ -0,0 +1,189 @@
2007-12-13 Marek Habersack <mhabersack@novell.com>
* MailAddress.cs, SmtpClient.cs, MailMessageWrapper.cs: speed
optimization - use String.Concat instead of String.Format in some
cases.
2007-11-09 Marek Habersack <mhabersack@novell.com>
* SmtpClient.cs: Connect only after reading in the fields that may
specify the port to connect to. Fixes bug #340501. Patch submitted
by Hubert FONGARNAND <informatique.internet@fiducial.fr>, thanks!
Mon Jul 9 13:04:37 CEST 2007 Paolo Molaro <lupus@ximian.com>
* SmtpClient.cs: fixed Vladimir's refactoring that broke
loading Mono.Security.
2006-08-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* MailAddress.cs: allow the space before '<' to be omitted.
2006-04-26 Vladimir Krasnov <vladimirk@mainsoft.com>
* SmtpClient.cs, SmtpStream.cs: Added SMTP over TLS support,
refactoring
2006-03-23 Vladimir Krasnov <vladimirk@mainsoft.com>
* SmtpMail.cs: removed TARGET_JVM part from Send method.
2006-03-23 Vladimir Krasnov <vladimirk@mainsoft.com>
* MailMessageWrapper.cs: fixed Fields property, casting to string
changed to ToString method call.
2006-01-08 Konstantin Triger <kostat@mainsoft.com>
* SmtpClient.cs, SmtpMail.cs, MailMessage.cs, MailMessageWrapper.cs,
MailAttachment.cs: TARGET_JVM changes to let the compilation
pass with csc 1.1.
2005-11-28 Chris Toshok <toshok@ximian.com>
* SmtpClient.cs: ignore warning 618 (obsolete) when compiling an
already obsolete api (in the 2.0 case).
* MailAttachment.cs: same.
* MailMessageWrapper.cs: same.
* MailMessage.cs: same.
2005-09-15 Gert Driesen <drieseng@users.sourceforge.net>
* MailPriority.cs: Marked obsolete in 2.0 profile. Fixed line endings.
* SmtpMail.cs: Added workaround message to ensure same warning is
generated as MS.NET 2.0.
* MailMessage.cs: same and fixed line endings. Set eol-style to native.
* MailEncoding.cs: same.
* MailFormat.cs: same.
* MailAttachment.cs: same.
2005-09-13 Sebastien Pouliot <sebastien@ximian.com>
* SmtpMail.cs: Added an Assert for FileIOPermission so it's possible
to send attachments (in this case MailAttachment is already protected
but doesn't open|read the file itself).
2005-09-09 Sebastien Pouliot <sebastien@ximian.com>
* MailAttachment.cs: Added [Link|Inheritance]Demand for Minimal. Added
FileIOPermission for Read in the constructor. Added [Obsolete] in 2.0.
* MailEncoding.cs: Removed [Serializable] and added [Obsolete] in 2.0.
* MailFormat.cs: Removed [Serializable] and added [Obsolete] in 2.0.
* MailMessage.cs: Removed references to RelatedBodyParts (2.0). Added
[Link|Inheritance]Demand for Minimal. Added [Obsolete] in 2.0.
* MailMessageWrapper.cs: Removed references to RelatedBodyParts (2.0).
* MailPriority.cs: Removed [Serializable] in 2.0. No [Obsolete] ?
* SmtpClient.cs: Removed references to RelatedBodyParts (2.0).
* SmtpMail.cs: Added [Link|Inheritance]Demand for Minimal. Added
Demand for Medium on Send method.Added [Obsolete] in 2.0.
2005-06-08 Ilya Kharmatsky <ilyak-at-mainsoft.com>
* SmtpMail.cs: Added TARGET_JVM directive in Send method,
where we will use in J2EE configuration the "native" java
support for obtaining the network address of localhost.
2005-04-20 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* SmtpClient.cs:
* SmtpStream.cs: removed warnings.
2005-01-28 Lluis Sanchez Gual <lluis@novell.com>
* Base64AttachmentEncoder.cs: Fixed warning.
2004-10-27 Sanjay Gupta <gsanjay@novell.com>
* SmtpClient.cs: Fix for bug 68829.
2004-08-27 Sanjay Gupta <gsanjay@novell.com>
* MailMessageWrapper.cs: Added a comment to add Date header.
* SmtpClient.cs: Updated functionality to add RelatedBodyPart to
MIME message.
2004-08-26 Sanjay Gupta <gsanjay@novell.com>
* SmtpClient.cs: Added functionality to add RelatedBodyPart to
MIME message.
2004-08-25 Sanjay Gupta <gsanjay@novell.com>
* MailMessageWrapper.cs: Added NET_2_0 property and another missing
property from NET_1_1.
* RelatedBodyPart.cs: Error detection and handling.
* SmtpClient.cs: Upgraded for NET_1_1 and WIP for NET_2_0.
2004-08-18 Sanjay Gupta <gsanjay@novell.com>
* MailEncoding.cs:
* MailFormat.cs:
* MailPriority.cs: Added NET_2_0 attribute.
2004-08-18 Sanjay Gupta <gsanjay@novell.com>
* MailMessage.cs: Added new property RelatedBodyParts.
* RelatedBodyPart.cs: Added new file.
2004-08-10 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* SmtpClient.cs: multipart mails default body format is now the same as
the one used for single part mails instead of being forced to
"text/plain".
2004-02-27 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* MailMessage.cs: patch by John Luke that initialized the fields in
the message and makes Fields return the same as in MS.NET. Fixes bug
#54908.
2003-12-18 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* MailMessage.cs: added Fields property.
2003-11-20 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* MailMessageWrapper.cs: fixed typo that made all messages be sent as
html, even when the body is marked as text. Path by Mohammad DAMT.
Closes bug #51177.
2003-07-03 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* MailAddress.cs: return null instead of exception when the address is
empty.
* MailAddressCollection.cs: ignore null addresses.
* SmtpMail.cs: add the exception we get as inner exception so we know
where the error is.
Fixes bug #45746.
2003-03-24 Per Arneng <pt99par@student.bth.se>
* MailUtil: Added for some functions that didnt fit in other classes
2003-03-06 Per Arneng <pt99par@student.bth.se>
* MailMessageWrapper: Added to get at more advanced mail message
2003-02-23 Per Arneng <pt99par@student.bth.se>
* SmtpMail.cs: Send method now implemented (needs testing)
* SmtpClient.cs: Added to make Send work (internal class)
* SmtpException.cs: Added to make Send work (internal class)
* SmtpStream.cs: Added to make Send work (internal class)
* SmtpResponse.cs: Added to make Send work (internal class)
2002-11-26 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* SmtpMail.cs: i don't wanna see that warning :-).
2002-04-26 Lawrence Pit <loz@cable.a2000.nl>
* MailAttachment.cs: Implemented
* MailEncoding.cs: Implemented
* MailFormat.cs: Implemented
* MailMessage.cs: Implemented
* MailPriority.cs: Implemented
* SmtpMail.cs: Stubbed

View File

@@ -0,0 +1,39 @@
//
// System.Web.Mail.IAttachmentEncoder.cs
//
// Author(s):
// Per Arneng <pt99par@student.bth.se>
//
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IO;
namespace System.Web.Mail {
// An interface for attachment encoders ex Base64, UUEncode
interface IAttachmentEncoder {
void EncodeStream( Stream ins , Stream outs );
}
}

View File

@@ -0,0 +1,131 @@
//
// System.Web.Mail.MailAddress.cs
//
// Author(s):
// Per Arneng <pt99par@student.bth.se>
//
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Text;
namespace System.Web.Mail {
// Reperesents a mail address
internal class MailAddress {
protected string user;
protected string host;
protected string name;
public string User {
get { return user; }
set { user = value; }
}
public string Host {
get { return host; }
set { host = value; }
}
public string Name {
get { return name; }
set { name = value; }
}
public string Address {
get { return String.Concat (user, "@", host); }
set {
string[] parts = value.Split( new char[] { '@' } );
if( parts.Length != 2 )
throw new FormatException( "Invalid e-mail address: '" + value + "'.");
user = parts[ 0 ];
host = parts[ 1 ];
}
}
public static MailAddress Parse( string str ) {
if (str == null || str.Trim () == "")
return null;
MailAddress addr = new MailAddress();
string address = null;
string nameString = null;
string[] parts = str.Split( new char[] { ' ', '<' } );
// find the address: xxx@xx.xxx
// and put to gether all the parts
// before the address as nameString
foreach( string part in parts ) {
if( part.IndexOf( '@' ) > 0 ) {
address = part;
break;
}
nameString = nameString + part + " ";
}
if( address == null )
throw new FormatException( "Invalid e-mail address: '" + str + "'.");
address = address.Trim( new char[] { '<' , '>' , '(' , ')' } );
addr.Address = address;
if( nameString != null ) {
addr.Name = nameString.Trim( new char[] { ' ' , '"' } );
addr.Name = ( addr.Name.Length == 0 ? null : addr.Name );
}
return addr;
}
public override string ToString() {
string retString = "";
if( name == null ) {
retString = String.Concat ("<", this.Address, ">");
} else {
string personName = this.Name;
if( MailUtil.NeedEncoding( personName ))
personName = "=?" + Encoding.Default.BodyName + "?B?" + MailUtil.Base64Encode(personName) + "?=";
retString = "\"" + personName + "\" <" + this.Address + ">";
}
return retString;
}
}
}

View File

@@ -0,0 +1,89 @@
//
// System.Web.Mail.MailAddressCollection.cs
//
// Author(s):
// Per Arneng <pt99par@student.bth.se>
//
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Text;
using System.Collections;
namespace System.Web.Mail {
// represents a collection of MailAddress objects
internal class MailAddressCollection : IEnumerable {
protected ArrayList data = new ArrayList();
public MailAddress this[ int index ] {
get { return this.Get( index ); }
}
public int Count { get { return data.Count; } }
public void Add( MailAddress addr ) { data.Add( addr ); }
public MailAddress Get( int index ) { return (MailAddress)data[ index ]; }
public IEnumerator GetEnumerator() {
return data.GetEnumerator();
}
public override string ToString() {
StringBuilder builder = new StringBuilder();
for( int i = 0; i <data.Count ; i++ ) {
MailAddress addr = this.Get( i );
builder.Append( addr );
if( i != ( data.Count - 1 ) ) builder.Append( ",\r\n " );
}
return builder.ToString();
}
public static MailAddressCollection Parse( string str ) {
if( str == null ) throw new ArgumentNullException("Null is not allowed as an address string");
MailAddressCollection list = new MailAddressCollection();
string[] parts = str.Split( new char[] { ',' , ';' } );
foreach( string part in parts ) {
MailAddress add = MailAddress.Parse (part);
if (add == null)
continue;
list.Add (add);
}
return list;
}
}
}

View File

@@ -0,0 +1,79 @@
//
// System.Web.Mail.MailAttachment.cs
//
// Author:
// Lawrence Pit (loz@cable.a2000.nl)
// Per Arneng (pt99par@student.bth.se)
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.IO;
using System.Security;
using System.Security.Permissions;
namespace System.Web.Mail
{
#if !NET_4_0
// CAS
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
#endif
[Obsolete ("The recommended alternative is System.Net.Mail.Attachment. http://go.microsoft.com/fwlink/?linkid=14202")]
public class MailAttachment
{
string filename;
MailEncoding encoding;
public MailAttachment (string filename) :
this (filename, MailEncoding.Base64)
{
}
public MailAttachment (string filename, MailEncoding encoding)
{
if (SecurityManager.SecurityEnabled) {
new FileIOPermission (FileIOPermissionAccess.Read, filename).Demand ();
}
if (!File.Exists (filename)) {
string msg = Locale.GetText ("Cannot find file: '{0}'.");
throw new HttpException (String.Format (msg, filename));
}
this.filename = filename;
this.encoding = encoding;
}
// Properties
public string Filename
{
get { return filename; }
}
public MailEncoding Encoding
{
get { return encoding; }
}
}
}

View File

@@ -0,0 +1,36 @@
//
// System.Web.Mail.MailEncoding.cs
//
// Author:
// Lawrence Pit (loz@cable.a2000.nl)
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Web.Mail
{
[Obsolete ("The recommended alternative is System.Net.Mime.TransferEncoding. http://go.microsoft.com/fwlink/?linkid=14202")]
public enum MailEncoding {
UUEncode,
Base64
}
}

View File

@@ -0,0 +1,36 @@
//
// System.Web.Mail.MailFormat.cs
//
// Author:
// Lawrence Pit (loz@cable.a2000.nl)
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Web.Mail
{
[Obsolete ("The recommended alternative is System.Net.Mail.MailMessage.IsBodyHtml. http://go.microsoft.com/fwlink/?linkid=14202")]
public enum MailFormat {
Text,
Html
}
}

View File

@@ -0,0 +1,113 @@
//
// System.Web.Mail.MailHeader.cs
//
// Author(s):
// Per Arneng <pt99par@student.bth.se>
//
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Collections.Specialized;
namespace System.Web.Mail {
// This class represents the header of a mail with
// all the header fields.
internal class MailHeader {
protected NameValueCollection data = new NameValueCollection();
public string To {
get { return data[ "To" ]; }
set { data[ "To" ] = value; }
}
public string From {
get { return data[ "From" ]; }
set { data[ "From" ] = value; }
}
public string Cc {
get { return data[ "Cc" ]; }
set { data[ "Cc" ] = value; }
}
public string Bcc {
get { return data[ "Bcc" ]; }
set { data[ "Bcc" ] = value; }
}
public string Subject {
get { return data[ "Subject" ]; }
set { data[ "Subject" ] = value; }
}
public string Importance {
get { return data[ "Importance" ]; }
set { data[ "Importance" ] = value; }
}
public string Priority {
get { return data[ "Priority" ]; }
set { data[ "Priority" ] = value; }
}
public string MimeVersion {
get { return data[ "Mime-Version" ]; }
set { data[ "Mime-Version" ] = value; }
}
public string ContentType {
get { return data[ "Content-Type" ]; }
set { data[ "Content-Type" ] = value; }
}
public string ContentTransferEncoding{
get { return data[ "Content-Transfer-Encoding" ]; }
set { data[ "Content-Transfer-Encoding" ] = value; }
}
public string ContentDisposition {
get { return data[ "Content-Disposition" ]; }
set { data[ "Content-Disposition" ] = value; }
}
public string ContentBase {
get { return data[ "Content-Base" ]; }
set { data[ "Content-Base" ] = value; }
}
public string ContentLocation {
get { return data[ "Content-Location" ]; }
set { data[ "Content-Location" ] = value; }
}
public NameValueCollection Data {
get { return data; }
}
}
}

View File

@@ -0,0 +1,141 @@
//
// System.Web.Mail.MailMessage.cs
//
// Author:
// Lawrence Pit (loz@cable.a2000.nl)
// Per Arneng (pt99par@student.bth.se)
// Sanjay Gupta (gsanjay@novell.com)
//
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections;
using System.Collections.Specialized;
using System.Security.Permissions;
using System.Text;
namespace System.Web.Mail
{
#if !NET_4_0
// CAS
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
#endif
[Obsolete ("The recommended alternative is System.Net.Mail.MailMessage. http://go.microsoft.com/fwlink/?linkid=14202")]
public class MailMessage
{
ArrayList attachments;
string bcc;
string body = String.Empty;
Encoding bodyEncoding;
MailFormat bodyFormat;
string cc;
string from;
ListDictionary headers;
MailPriority priority;
string subject = String.Empty;
string to;
string urlContentBase;
string urlContentLocation;
// Constructor
public MailMessage ()
{
attachments = new ArrayList (8);
headers = new ListDictionary ();
bodyEncoding = Encoding.Default;
fields = new Hashtable ();
}
// Properties
public IList Attachments {
get { return (IList) attachments; }
}
public string Bcc {
get { return bcc; }
set { bcc = value; }
}
public string Body {
get { return body; }
set { body = value; }
}
public Encoding BodyEncoding {
get { return bodyEncoding; }
set { bodyEncoding = value; }
}
public MailFormat BodyFormat {
get { return bodyFormat; }
set { bodyFormat = value; }
}
public string Cc {
get { return cc; }
set { cc = value; }
}
public string From {
get { return from; }
set { from = value; }
}
public IDictionary Headers {
get { return (IDictionary) headers; }
}
public MailPriority Priority {
get { return priority; }
set { priority = value; }
}
public string Subject {
get { return subject; }
set { subject = value; }
}
public string To {
get { return to; }
set { to = value; }
}
public string UrlContentBase {
get { return urlContentBase; }
set { urlContentBase = value; }
}
public string UrlContentLocation {
get { return urlContentLocation; }
set { urlContentLocation = value; }
}
Hashtable fields;
public IDictionary Fields {
get {
return (IDictionary) fields;
}
}
}
}

View File

@@ -0,0 +1,243 @@
//
// System.Web.Mail.MailMessageWrapper.cs
//
// Author(s):
// Per Arneng <pt99par@student.bth.se>
// Sanjay Gupta <gsanjay@novell.com>
//
// (C) 2004, Novell, Inc. (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections;
using System.Text;
namespace System.Web.Mail {
// wraps a MailMessage to make an easier
// interface to work with collections of
// addresses instead of a single string
internal class MailMessageWrapper {
MailAddressCollection bcc = new MailAddressCollection();
MailAddressCollection cc = new MailAddressCollection();
MailAddress from;
MailAddressCollection to = new MailAddressCollection();
MailHeader header = new MailHeader();
MailMessage message;
string body;
// Constructor
public MailMessageWrapper( MailMessage message )
{
this.message = message;
if( message.From != null ) {
from = MailAddress.Parse( message.From );
header.From = from.ToString();
}
if( message.To != null ) {
to = MailAddressCollection.Parse( message.To );
header.To = to.ToString();
}
if( message.Cc != null ) {
cc = MailAddressCollection.Parse( message.Cc );
header.Cc = cc.ToString();
}
if( message.Bcc != null ) {
bcc = MailAddressCollection.Parse( message.Bcc );
header.Bcc = bcc.ToString();
}
// set the subject
if( message.Subject != null ) {
// encode the subject if it needs encoding
if( MailUtil.NeedEncoding( message.Subject ) ) {
byte[] subjectBytes = message.BodyEncoding.GetBytes( message.Subject );
// encode the subject with Base64
header.Subject = "=?" + message.BodyEncoding.BodyName + "?B?" + Convert.ToBase64String (subjectBytes) + "?=";
} else {
header.Subject = message.Subject;
}
}
// convert single '.' on a line with ".." to not
// confuse the smtp server since the DATA command
// is terminated with a '.' on a single line.
// this is also according to the smtp specs.
if( message.Body != null ) {
body = message.Body.Replace( "\n.\n" , "\n..\n" );
body = body.Replace( "\r\n.\r\n" , "\r\n..\r\n" );
}
// set the Contet-Base header
if( message.UrlContentBase != null )
header.ContentBase = message.UrlContentBase;
// set the Contet-Location header
if( message.UrlContentLocation != null )
header.ContentLocation = message.UrlContentLocation;
// set the content type
switch( message.BodyFormat ) {
case MailFormat.Html:
header.ContentType = String.Concat ( "text/html; charset=\"", message.BodyEncoding.BodyName, "\"");
break;
case MailFormat.Text:
header.ContentType = String.Concat ( "text/plain; charset=\"", message.BodyEncoding.BodyName, "\"");
break;
default:
header.ContentType = String.Concat ( "text/html; charset=\"", message.BodyEncoding.BodyName, "\"");
break;
}
// set the priority as in the same way as .NET sdk does
switch( message.Priority ) {
case MailPriority.High:
header.Importance = "high";
break;
case MailPriority.Low:
header.Importance = "low";
break;
case MailPriority.Normal:
header.Importance = "normal";
break;
default:
header.Importance = "normal";
break;
}
// .NET sdk allways sets this to normal
header.Priority = "normal";
// Set the mime version
header.MimeVersion = "1.0";
// Set the transfer encoding
if( message.BodyEncoding is ASCIIEncoding ) {
header.ContentTransferEncoding = "7bit";
} else {
header.ContentTransferEncoding = "8bit";
}
// Add Date header, we were missing earlier 27/08/04
// RFC822 requires date to be in format Fri, 27 Aug 2004 20:13:20 +0530
//DateTime.Now gives in format 8/27/2004 8:13:00 PM
// Need to explore further dateTime formats available or do we need
// to write a function to convert.
//header.Data.Add ("Date", DateTime.Now.ToString());
// Add the custom headers
foreach( string key in message.Headers.Keys )
header.Data[ key ] = (string)this.message.Headers[ key ];
}
// Properties
public IList Attachments {
get { return message.Attachments; }
}
public MailAddressCollection Bcc {
get { return bcc; }
}
public string Body {
get { return body; }
set { body = value; }
}
public Encoding BodyEncoding {
get { return message.BodyEncoding; }
set { message.BodyEncoding = value; }
}
public MailFormat BodyFormat {
get { return message.BodyFormat; }
set { message.BodyFormat = value; }
}
public MailAddressCollection Cc {
get { return cc; }
}
public MailAddress From {
get { return from; }
}
public MailHeader Header {
get { return header; }
}
public MailPriority Priority {
get { return message.Priority; }
set { message.Priority = value; }
}
public string Subject {
get { return message.Subject; }
set { message.Subject = value; }
}
public MailAddressCollection To {
get { return to; }
}
public string UrlContentBase {
get { return message.UrlContentBase; }
}
public string UrlContentLocation {
get { return message.UrlContentLocation; }
}
public MailHeader Fields {
get {
MailHeader bodyHeaders = new MailHeader();
// Add Fields to MailHeader Object
foreach( string key in message.Fields.Keys )
bodyHeaders.Data[ key ] = this.message.Fields[ key ].ToString();
return bodyHeaders;
}
}
}
}

View File

@@ -0,0 +1,37 @@
//
// System.Web.Mail.MailPriority.cs
//
// Author:
// Lawrence Pit (loz@cable.a2000.nl)
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Web.Mail
{
[Obsolete ("The recommended alternative is System.Net.Mail.MailPriority. http://go.microsoft.com/fwlink/?linkid=14202")]
public enum MailPriority {
Normal,
Low,
High
}
}

View File

@@ -0,0 +1,88 @@
//
// System.Web.Mail.MailUtil.cs
//
// Author(s):
// Per Arneng <pt99par@student.bth.se>
//
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Text;
namespace System.Web.Mail {
// This class contains some utillity functions
// that doesnt fit in other classes and to keep
// high cohesion on the other classes.
internal class MailUtil {
// determines if a string needs to
// be encoded for transfering over
// the smtp protocol without risking
// that it would be changed.
public static bool NeedEncoding( string str ) {
foreach( char chr in str ) {
int ch = (int)chr;
if( ! ( (ch > 61) && (ch < 127) || (ch>31) && (ch<61) ) ) {
return true;
}
}
return false;
}
// Encodes a string to base4
public static string Base64Encode( string str ) {
return Convert.ToBase64String( Encoding.Default.GetBytes( str ) );
}
// Generate a unique boundary
public static string GenerateBoundary() {
StringBuilder boundary = new StringBuilder("__MONO__Boundary");
boundary.Append("__");
DateTime now = DateTime.Now;
boundary.Append(now.Year);
boundary.Append(now.Month);
boundary.Append(now.Day);
boundary.Append(now.Hour);
boundary.Append(now.Minute);
boundary.Append(now.Second);
boundary.Append(now.Millisecond);
boundary.Append("__");
boundary.Append((new Random()).Next());
boundary.Append("__");
return boundary.ToString();
}
}
}

View File

@@ -0,0 +1,72 @@
//
// System.Web.Mail.RelatedBodyPart.cs
//
// Authors:
// Sanjay Gupta (gsanjay@novell.com)
//
// (C) 2004 Novell, Inc (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System.Web;
namespace System.Web.Mail
{
public class RelatedBodyPart
{
string id;
string fileName;
public RelatedBodyPart (string id, string fileName)
{
this.id = id;
if (FileExists (fileName))
this.fileName = fileName;
else
throw new HttpException(500, "Invalid related body part");
}
public string Name {
get { return id; }
set { id = value; }
}
public string Path {
get { return fileName; }
set { fileName = value; }
}
bool FileExists (string fileName)
{
//I am handling local files only . Not sure how URL's
//need to be handled.
try {
System.IO.File.OpenRead (fileName).Close ();
return true;
} catch (Exception) {
return false;
}
}
}
}
#endif

View File

@@ -0,0 +1,299 @@
//
// System.Web.Mail.SmtpClient.cs
//
// Author(s):
// Per Arneng <pt99par@student.bth.se>
// Sanjay Gupta <gsanjay@novell.com>
// (C) 2004, Novell, Inc. (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Net;
using System.IO;
using System.Text;
using System.Collections;
using System.Net.Sockets;
using System.Security.Permissions;
using System.Reflection;
namespace System.Web.Mail {
/// represents a conntection to a smtp server
internal class SmtpClient
{
string server;
TcpClient tcpConnection;
SmtpStream smtp;
string username;
string password;
int port = 25;
bool usessl = false;
short authenticate = 1;
//Initialise the variables and connect
public SmtpClient (string server)
{
this.server = server;
}
// make the actual connection
// and HELO handshaking
void Connect ()
{
tcpConnection = new TcpClient (server, port);
NetworkStream stream = tcpConnection.GetStream ();
smtp = new SmtpStream (stream);
}
void ChangeToSSLSocket ()
{
#if TARGET_JVM
java.lang.Class c = vmw.common.TypeUtils.ToClass (smtp.Stream);
java.lang.reflect.Method m = c.getMethod ("ChangeToSSLSocket", null);
m.invoke (smtp.Stream, new object[]{});
#else
// Load Mono.Security.dll
Assembly a;
try {
a = Assembly.Load (Consts.AssemblyMono_Security);
} catch (System.IO.FileNotFoundException) {
throw new SmtpException ("Cannot load Mono.Security.dll");
}
Type tSslClientStream = a.GetType ("Mono.Security.Protocol.Tls.SslClientStream");
object[] consArgs = new object[4];
consArgs[0] = smtp.Stream;
consArgs[1] = server;
consArgs[2] = true;
Type tSecurityProtocolType = a.GetType ("Mono.Security.Protocol.Tls.SecurityProtocolType");
int nSsl3Val = (int) Enum.Parse (tSecurityProtocolType, "Ssl3");
int nTlsVal = (int) Enum.Parse (tSecurityProtocolType, "Tls");
consArgs[3] = Enum.ToObject (tSecurityProtocolType, nSsl3Val | nTlsVal);
object objSslClientStream = Activator.CreateInstance (tSslClientStream, consArgs);
if (objSslClientStream != null)
smtp = new SmtpStream ((Stream)objSslClientStream);
#endif
}
void ReadFields (MailMessageWrapper msg)
{
string tmp;
username = msg.Fields.Data ["http://schemas.microsoft.com/cdo/configuration/sendusername"];
password = msg.Fields.Data ["http://schemas.microsoft.com/cdo/configuration/sendpassword"];
tmp = msg.Fields.Data ["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"];
if (tmp != null)
authenticate = short.Parse (tmp);
tmp = msg.Fields.Data ["http://schemas.microsoft.com/cdo/configuration/smtpusessl"];
if (tmp != null)
usessl = bool.Parse (tmp);
tmp = msg.Fields.Data ["http://schemas.microsoft.com/cdo/configuration/smtpserverport"];
if (tmp != null)
port = int.Parse (tmp);
}
void StartSend (MailMessageWrapper msg)
{
ReadFields (msg);
Connect ();
// read the server greeting
smtp.ReadResponse ();
smtp.CheckForStatusCode (220);
if (usessl || (username != null && password != null && authenticate != 1))
{
smtp.WriteEhlo (Dns.GetHostName ());
if (usessl) {
bool isSSL = smtp.WriteStartTLS ();
if (isSSL)
ChangeToSSLSocket ();
}
if (username != null && password != null && authenticate != 1) {
smtp.WriteAuthLogin ();
if (smtp.LastResponse.StatusCode == 334) {
smtp.WriteLine (Convert.ToBase64String (Encoding.ASCII.GetBytes (username)));
smtp.ReadResponse ();
smtp.CheckForStatusCode (334);
smtp.WriteLine (Convert.ToBase64String (Encoding.ASCII.GetBytes (password)));
smtp.ReadResponse ();
smtp.CheckForStatusCode (235);
}
}
} else {
smtp.WriteHelo (Dns.GetHostName ());
}
}
public void Send (MailMessageWrapper msg)
{
if (msg.From == null)
throw new SmtpException ("From property must be set.");
if (msg.To == null)
if (msg.To.Count < 1)
throw new SmtpException ("Atleast one recipient must be set.");
StartSend (msg);
// start with a reset incase old data
// is present at the server in this session
smtp.WriteRset ();
// write the mail from command
smtp.WriteMailFrom (msg.From.Address);
// write the rcpt to command for the To addresses
foreach (MailAddress addr in msg.To)
smtp.WriteRcptTo (addr.Address);
// write the rcpt to command for the Cc addresses
foreach (MailAddress addr in msg.Cc)
smtp.WriteRcptTo (addr.Address);
// write the rcpt to command for the Bcc addresses
foreach (MailAddress addr in msg.Bcc)
smtp.WriteRcptTo (addr.Address);
// write the data command and then
// send the email
smtp.WriteData ();
if (msg.Attachments.Count == 0)
SendSinglepartMail (msg);
else
SendMultipartMail (msg);
// write the data end tag "."
smtp.WriteDataEndTag ();
}
// sends a single part mail to the server
void SendSinglepartMail (MailMessageWrapper msg)
{
// write the header
smtp.WriteHeader (msg.Header);
// send the mail body
smtp.WriteBytes (msg.BodyEncoding.GetBytes (msg.Body));
}
// SECURITY-FIXME: lower assertion with imperative asserts
[FileIOPermission (SecurityAction.Assert, Unrestricted = true)]
// sends a multipart mail to the server
void SendMultipartMail (MailMessageWrapper msg)
{
// generate the boundary between attachments
string boundary = MailUtil.GenerateBoundary ();
// set the Content-Type header to multipart/mixed
string bodyContentType = msg.Header.ContentType;
msg.Header.ContentType = String.Concat ("multipart/mixed;\r\n boundary=", boundary);
// write the header
smtp.WriteHeader (msg.Header);
// write the first part text part
// before the attachments
smtp.WriteBoundary (boundary);
MailHeader partHeader = new MailHeader ();
partHeader.ContentType = bodyContentType;
// Add all the custom headers to body part as specified in
//Fields property of MailMessageWrapper
//Remove fields specific for authenticating to SMTP server.
//Need to incorporate AUTH command in SmtpStream to handle
//Authorization info. Its a temporary fix for Bug no 68829.
//Will dig some more on SMTP AUTH command, and then implement
//Authorization. - Sanjay
if (msg.Fields.Data ["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] != null)
msg.Fields.Data.Remove ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate");
if (msg.Fields.Data ["http://schemas.microsoft.com/cdo/configuration/sendusername"] != null)
msg.Fields.Data.Remove ("http://schemas.microsoft.com/cdo/configuration/sendusername");
if (msg.Fields.Data ["http://schemas.microsoft.com/cdo/configuration/sendpassword"] != null)
msg.Fields.Data.Remove ("http://schemas.microsoft.com/cdo/configuration/sendpassword");
partHeader.Data.Add (msg.Fields.Data);
smtp.WriteHeader (partHeader);
// FIXME: probably need to use QP or Base64 on everything higher
// then 8-bit .. like utf-16
smtp.WriteBytes (msg.BodyEncoding.GetBytes (msg.Body) );
smtp.WriteBoundary (boundary);
// now start to write the attachments
for (int i=0; i< msg.Attachments.Count ; i++) {
MailAttachment a = (MailAttachment)msg.Attachments[ i ];
FileInfo fileInfo = new FileInfo (a.Filename);
MailHeader aHeader = new MailHeader ();
aHeader.ContentType =
String.Concat (MimeTypes.GetMimeType (fileInfo.Name), "; name=\"", fileInfo.Name, "\"");
aHeader.ContentDisposition = String.Concat ("attachment; filename=\"", fileInfo.Name, "\"");
aHeader.ContentTransferEncoding = a.Encoding.ToString();
smtp.WriteHeader (aHeader);
// perform the actual writing of the file.
// read from the file stream and write to the tcp stream
FileStream ins = fileInfo.OpenRead ();
// create an apropriate encoder
IAttachmentEncoder encoder;
if (a.Encoding == MailEncoding.UUEncode)
encoder = new UUAttachmentEncoder (644, fileInfo.Name );
else
encoder = new Base64AttachmentEncoder ();
encoder.EncodeStream (ins, smtp.Stream);
ins.Close ();
smtp.WriteLine ("");
// if it is the last attachment write
// the final boundary otherwise write
// a normal one.
if (i < (msg.Attachments.Count - 1))
smtp.WriteBoundary (boundary);
else
smtp.WriteFinalBoundary (boundary);
}
}
// send quit command and
// closes the connection
public void Close()
{
smtp.WriteQuit();
tcpConnection.Close();
}
}
}

View File

@@ -0,0 +1,38 @@
//
// System.Web.Mail.SmtpException.cs
//
// Author(s):
// Per Arneng <pt99par@student.bth.se>
//
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.IO;
namespace System.Web.Mail {
// an exception thrown when an smtp exception occurs
internal class SmtpException : IOException {
public SmtpException( string message ) : base( message ) {}
}
}

View File

@@ -0,0 +1,112 @@
//
// System.Web.Mail.SmtpMail.cs
//
// Author:
// Lawrence Pit (loz@cable.a2000.nl)
// Per Arneng (pt99par@student.bth.se) (SmtpMail.Send)
//
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.IO;
using System.Reflection;
using System.Security.Permissions;
namespace System.Web.Mail
{
// CAS
[Obsolete ("The recommended alternative is System.Net.Mail.SmtpClient. http://go.microsoft.com/fwlink/?linkid=14202")]
#if !NET_4_0
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
#endif
public class SmtpMail
{
static string smtpServer = "localhost";
// Constructor
SmtpMail ()
{
/* empty */
}
// Properties
public static string SmtpServer {
get { return smtpServer; }
set { smtpServer = value; }
}
// Medium (not Minimal) here
// http://msdn.microsoft.com/library/en-us/dnpag2/html/paght000017.asp
[AspNetHostingPermission (SecurityAction.Demand, Level = AspNetHostingPermissionLevel.Medium)]
public static void Send (MailMessage message)
{
try {
// wrap the MailMessage in a MailMessage wrapper for easier
// access to properties and to add some functionality
MailMessageWrapper messageWrapper = new MailMessageWrapper( message );
SmtpClient smtp = new SmtpClient (smtpServer);
smtp.Send (messageWrapper);
smtp.Close ();
} catch (SmtpException ex) {
// LAMESPEC:
// .NET sdk throws HttpException
// for some reason so to be compatible
// we have to do it to :(
throw new HttpException (ex.Message, ex);
} catch (IOException ex) {
throw new HttpException (ex.Message, ex);
} catch (FormatException ex) {
throw new HttpException (ex.Message, ex);
} catch (SocketException ex) {
throw new HttpException (ex.Message, ex);
}
}
public static void Send (string from, string to, string subject, string messageText)
{
MailMessage message = new MailMessage ();
message.From = from;
message.To = to;
message.Subject = subject;
message.Body = messageText;
Send (message);
}
}
}

View File

@@ -0,0 +1,86 @@
//
// System.Web.Mail.SmtpResponse.cs
//
// Author(s):
// Per Arneng <pt99par@student.bth.se>
//
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
namespace System.Web.Mail {
/// this class represents the response from the smtp server
internal class SmtpResponse {
string rawResponse;
int statusCode;
string[] parts;
/// use the Parse method to create instances
protected SmtpResponse() {}
/// the smtp status code FIXME: change to Enumeration?
public int StatusCode {
get { return statusCode; }
set { statusCode = value; }
}
/// the response as it was recieved
public string RawResponse {
get { return rawResponse; }
set { rawResponse = value; }
}
/// the response as parts where ; was used as delimiter
public string[] Parts {
get { return parts; }
set { parts = value; }
}
/// parses a new response object from a response string
public static SmtpResponse Parse( string line ) {
SmtpResponse response = new SmtpResponse();
if( line.Length < 4 )
throw new SmtpException( "Response is to short " +
line.Length + ".");
if( ( line[ 3 ] != ' ' ) && ( line[ 3 ] != '-' ) )
throw new SmtpException( "Response format is wrong.(" +
line + ")" );
// parse the response code
response.StatusCode = Int32.Parse( line.Substring( 0 , 3 ) );
// set the rawsponse
response.RawResponse = line;
// set the response parts
response.Parts = line.Substring( 0 , 3 ).Split( ';' );
return response;
}
}
}

View File

@@ -0,0 +1,239 @@
//
// System.Web.Mail.SmtpStream.cs
//
// Author(s):
// Per Arneng <pt99par@student.bth.se>
//
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.IO;
using System.Collections;
using System.Text;
using System.Diagnostics;
namespace System.Web.Mail {
internal class SmtpStream {
protected Stream stream;
protected Encoding encoding;
protected SmtpResponse lastResponse;
protected string command = "";
public SmtpStream( Stream stream ) {
this.stream = stream;
encoding = new ASCIIEncoding();
}
public Stream Stream {
get { return stream; }
}
public SmtpResponse LastResponse {
get { return lastResponse; }
}
public void WriteRset() {
command = "RSET";
WriteLine( command );
ReadResponse();
CheckForStatusCode( 250 );
}
public void WriteAuthLogin()
{
command = "AUTH LOGIN";
WriteLine( command );
ReadResponse();
}
public bool WriteStartTLS( )
{
command = "STARTTLS";
WriteLine( command );
ReadResponse();
return LastResponse.StatusCode == 220;
}
public void WriteEhlo( string hostName )
{
command = "EHLO " + hostName;
WriteLine( command );
ReadResponse();
CheckForStatusCode( 250 );
}
public void WriteHelo( string hostName ) {
command = "HELO " + hostName;
WriteLine( command );
ReadResponse();
CheckForStatusCode( 250 );
}
public void WriteMailFrom( string from ) {
command = "MAIL FROM: <" + from + ">";
WriteLine( command );
ReadResponse();
CheckForStatusCode( 250 );
}
public void WriteRcptTo( string to ) {
command = "RCPT TO: <" + to + ">";
WriteLine( command );
ReadResponse();
CheckForStatusCode( 250 );
}
public void WriteData() {
command = "DATA";
WriteLine( command );
ReadResponse();
CheckForStatusCode( 354 );
}
public void WriteQuit() {
command = "QUIT";
WriteLine( command );
ReadResponse();
CheckForStatusCode( 221 );
}
public void WriteBoundary( string boundary ) {
WriteLine( "\r\n--{0}" , boundary );
}
public void WriteFinalBoundary( string boundary ) {
WriteLine( "\r\n--{0}--" , boundary );
}
// single dot by itself
public void WriteDataEndTag() {
command = "\r\n.";
WriteLine( command );
ReadResponse();
CheckForStatusCode( 250 );
}
public void WriteHeader( MailHeader header ) {
// write the headers
foreach( string key in header.Data.AllKeys )
WriteLine( "{0}: {1}" , key , header.Data[ key ] );
// write the header end tag
WriteLine( "" );
}
public void CheckForStatusCode( int statusCode ) {
if( LastResponse.StatusCode != statusCode ) {
string msg = "" +
"Server reponse: '" + lastResponse.RawResponse + "';" +
"Status code: '" + lastResponse.StatusCode + "';" +
"Expected status code: '" + statusCode + "';" +
"Last command: '" + command + "'";
throw new SmtpException( msg );
}
}
// write buffer's bytes to the stream
public void WriteBytes( byte[] buffer ) {
stream.Write( buffer , 0 , buffer.Length );
}
// writes a formatted line to the server
public void WriteLine( string format , params object[] args ) {
WriteLine( String.Format( format , args ) );
}
// writes a line to the server
public void WriteLine( string line ) {
byte[] buffer = encoding.GetBytes( line + "\r\n" );
stream.Write( buffer , 0 , buffer.Length );
Debug.WriteLine ("smtp: {0}", line);
}
// read a line from the server
public void ReadResponse( ) {
byte[] buffer = new byte [512];
int position = 0;
bool lastLine = false;
do {
int readLength = stream.Read (buffer , position , buffer.Length - position);
if (readLength > 0) {
int available = position + readLength - 1;
if (available > 4 && (buffer [available] == '\n' || buffer [available] == '\r'))
for (int index = available - 3; ; index--) {
if (index < 0 || buffer [index] == '\n' || buffer [index] == '\r') {
lastLine = buffer [index + 4] == ' ';
break;
}
}
// move position
position += readLength;
// check if buffer is full
if (position == buffer.Length) {
byte [] newBuffer = new byte [buffer.Length * 2];
Array.Copy (buffer, 0, newBuffer, 0, buffer.Length);
buffer = newBuffer;
}
}
} while(!lastLine);
string line = encoding.GetString (buffer , 0 , position - 1);
// parse the line to the lastResponse object
lastResponse = SmtpResponse.Parse (line);
Debug.WriteLine ("smtp: {0}", line);
}
}
}

View File

@@ -0,0 +1,133 @@
//
// System.Web.Mail.ToUUEncodingTransform.cs
//
// Author(s):
// Per Arneng <pt99par@student.bth.se>
//
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Security.Cryptography;
namespace System.Web.Mail {
// This class transforms blocks of plaintext to UU encoding
internal class ToUUEncodingTransform : ICryptoTransform {
public int InputBlockSize { get { return 45; } }
public int OutputBlockSize { get { return 61; } }
public bool CanTransformMultipleBlocks { get { return true; } }
public bool CanReuseTransform { get { return true; } }
// transforms a block of bytes to UU encoding
public int TransformBlock( byte[] inputBuffer,
int inputOffset,
int inputCount,
byte[] outputBuffer,
int outputOffset
) {
// write the line length length+0x20
outputBuffer[ 0 ] = (byte)'M';
// transform the block 3bytes at a time
for( int i=0;i<15;i++ ) {
TransformTriplet( inputBuffer , inputOffset + i * 3 , 3,
outputBuffer , outputOffset + i * 4 + 1);
}
return OutputBlockSize;
}
// make a final uu transformations
public byte[] TransformFinalBlock(byte[] inputBuffer,
int inputOffset,
int inputCount
) {
// calculate how many 4-byte blocks there are
int tripletBlocks = inputCount / 3 + 1;
// create a new buffer and copy the input data into that
byte[] buffer = new byte[ tripletBlocks * 3 ];
Buffer.BlockCopy( inputBuffer,inputOffset, buffer,0,inputCount);
// create the outpur buffer and set the first byte
// to the length+0x20
byte[] outputBuffer = new byte[ tripletBlocks * 4 + 1 ];
outputBuffer[ 0 ] = (byte)(inputCount+0x20);
// transform the block 3bytes at a time
for( int i =0 ; i < tripletBlocks ; i++ ) {
TransformTriplet( inputBuffer , inputOffset + i * 3 , 3,
outputBuffer , i * 4 + 1);
}
return outputBuffer;
}
// transforms a 3byte buffer to a 4byte uuencoded buffer
protected int TransformTriplet( byte[] inputBuffer,
int inputOffset,
int inputCount,
byte[] outputBuffer,
int outputOffset
) {
byte a = inputBuffer[ inputOffset + 0 ];
byte b = inputBuffer[ inputOffset + 1 ];
byte c = inputBuffer[ inputOffset + 2 ];
outputBuffer[ outputOffset + 0 ] =
(byte)(0x20 + (( a >> 2 ) & 0x3F));
outputBuffer[ outputOffset + 1 ] =
(byte)(0x20 + (((a << 4) | ((b >> 4) & 0xF)) & 0x3F));
outputBuffer[ outputOffset + 2 ] =
(byte)(0x20 + (((b << 2) | ((c >> 6) & 0x3)) & 0x3F));
outputBuffer[ outputOffset + 3 ] =
(byte)(0x20 + (( c ) & 0x3F));
// tanslate all 0x20 to 0x60 according to specs
for( int i = 0; i < 4; i++ ) {
if( outputBuffer[ outputOffset + i ] == 0x20 ) {
outputBuffer[ outputOffset + i ] = 0x60;
}
}
return 4;
}
public void Dispose() {}
}
}

Some files were not shown because too many files have changed in this diff Show More