|
Hi,
You must try, most of stuff compatibe with CF but there may be some IO related calls what not supported.
You can try an post results here.
|
|
|
|
|
Hi Ivar
Great job!
My company needs to know if it has permission to use, modify and distribute the code without restriction and under what terms (license) applies. We will not change any class name or namespaces.
Thanks,
Yaron
|
|
|
|
|
|
|
hi,
i need to set the rtf text data to a mime message body
how can i do that using your sample program.
or can i convert rtf text data to html data using mime message
api or interface ?
|
|
|
|
|
|
First of all let me say BRAVO! WOW! WOW! WOW!
You have provided a wonderful service to the developer community.
You have done something that no one else has done.
You have done it in native C#.
You have made it free.
You have even provided the source.
Thank you so, so, so much.
The world needs more people like you. If you have a PayPal account I will gladly make a contribution.
Now that my praise is done I have a few questions.
1. What would the code look like for a signed email? I found two postings regarding this topic but the last post remained unanswered.
Ideally I am looking for a full example of a message that is signed and encrypted using AES 256 CBC. There are specific requirements for the formatting of the message due to legacy constraints and I can't use multipart/smime, rather I have to use application/x-pkcs7-mime (I would think adding an additional static string property to the MIME_MediaTypes.Application class called x_pkcs7_mime would do the trick). I have been able to sign and encrypt using native .NET code but not with AES 256 CBC because .NET uses COM Interop to interface with the CryptoAPI that ships with Windows and no versions of Windows prior to Vista support AES 256 CBC. Windows Vista, Win2k8, Win7 use the CNG encryption library which replaces the older CryptoAPI. That being said, if you write code in VS and reference the AES 256 bit algorithm it will compile regardless of whether you are programming on Windows XP or Vista but it will only run on Vista, W2k8, Win7 etc. If you try to run the executable on any OS prior to Vista you get a runtime error telling you that the algorithm specified does not exist.
Anyhow, the issue I have been having (and I assume many other developers have as well) is one that you have gone to great lengths in solving, which is easily creating, reading, parsing, manipulating etc. MIME entities. I am also trying to read in body text that may or may not have already been signed/encrypted. How would you approach that type of scenario? Since haven't provided signing and encryption functionality (yet???) I have to do that first and then read in the already signed/encrypted bytes. Unfortunately, if I've already done the signing and encrypting then won't the data with various nested MimeParts that have already been encoded impossible?
2. I see that you have method stubs for signing and validating a signature but no code. Do you plan on adding methods any time soon? This would be fantastic! I would be willing to help you in your quest even if it meant writing all of the documentation, comments, spell check etc.
I know this is alot to ask so whatever help you can provide is greatly appreciated. Regards.
|
|
|
|
|
Hi,
>If you have a PayPal account I will gladly make a contribution.
ivar@lumisoft.ee
>I can't use multipart/smime, rather I have to use application/x-pkcs7-mim
>(I would think adding an additional static string property to the ...
I may add it, also you can do any application/xxx entity with general purpose MIME_b_Application class.
You say sign and encrypt, i doubt you can do both at same time, or you need nest entities(sign encypted entity).
Currently only way is you build all needed entties manually, by providing all headers, data needed.
About AES, you may look:
http://www.bouncycastle.org/csharp/[^]
If rember right it can do that.
But thats sure i won't make LumiSoft.Net.dll relay on that. You should use it in your custom app.
>I am also trying to read in body text that may or may not have already been signed
Signed message text part is readed out as normal text, only signature not checked.
Signature checking can't be done automatically, because some xx-lagorythm may be used and that causes message parsing to fail.
Encrypted message you can't read anyway, before you haven't provided key for the specifiec entity(each encrypted entity may have different key).
Mainly multipart/signed not completed because low interest. The low interest probably caused that mail servers may alter content a little, then signatures not valid. For example mail message must have CRLF lines per standard, some servers use LF - middle server may convert them to CRLF ....
There are probably more cases.
>2. I see that you have method stubs for signing and validating a signature but no code. Do you plan on adding methods any time soon?
Probably i add some code what will help to handle it more easely, but when 100% done, can't say.
|
|
|
|
|
I've been working with BouncyCastle. We had no other choice since we had to be backwards compatible with W2K3 Server and support AES 256 CBC. BouncyCastle can also read keys directly from a Java Keystore (JKS) something that none of the other providers (including Microsoft) can.
When you say "build the needed entities manually" do you mean using a StringBuilder and appending the text line-by-line? I saw examples of this and it seemed like the only way to do it before I found your code. Wouldn't I be able to make a "signature entity" and make the "encrypted entity" it's child?
The code below is the closest thing I've found to getting this to work. I am able to successfully produce an email that is signed and encrypted. It will open up in MS Outlook with the red and blue icons and allow me to view the message and information about the certificates.
I found the code from another guy who wrote some mail messaging libraries at http://www.codeproject.com/KB/security/CPI_NET_SecureMail.aspx.
public string SignContent(string UnencryptedContent)
{
string signatureBoundry = "--PTBoundry=2";
string signatureBoundry2 = "--PTBoundry=3";
StringBuilder fullUnsignedMessageBuilder = new StringBuilder();
fullUnsignedMessageBuilder.Append("Content-Type: ");
fullUnsignedMessageBuilder.Append("multipart/mixed;");
fullUnsignedMessageBuilder.Append(" boundary=\"");
fullUnsignedMessageBuilder.Append(signatureBoundry);
fullUnsignedMessageBuilder.Append("\"\r\n");
fullUnsignedMessageBuilder.Append("Content-Transfer-Encoding: ");
fullUnsignedMessageBuilder.Append(TransferEncoding.SevenBit);
fullUnsignedMessageBuilder.Append("\r\n");
fullUnsignedMessageBuilder.Append(UnencryptedContent);
string fullUnsignedMessage = fullUnsignedMessageBuilder.ToString();
byte[] SignedAndEncryptedContent = GetSignature(fullUnsignedMessage, GetSignCert(), GetEncryptionCert());
StringBuilder signedMessageBuilder = new StringBuilder();
signedMessageBuilder.Append("--");
signedMessageBuilder.Append(signatureBoundry2);
signedMessageBuilder.Append("\r\n");
signedMessageBuilder.Append(fullUnsignedMessage);
signedMessageBuilder.Append("\r\n");
signedMessageBuilder.Append("--");
signedMessageBuilder.Append(signatureBoundry2);
signedMessageBuilder.Append("\r\n");
signedMessageBuilder.Append("Content-Type: application/x-pkcs7-signature; name=\"smime.p7s\"\r\n");
signedMessageBuilder.Append("Content-Transfer-Encoding: base64\r\n");
signedMessageBuilder.Append("Content-Disposition: attachment; filename=\"smime.p7s\"\r\n\r\n");
signedMessageBuilder.Append(Convert.ToBase64String(SignedContent));
signedMessageBuilder.Append("\r\n\r\n");
signedMessageBuilder.Append("--");
signedMessageBuilder.Append(signatureBoundry2);
signedMessageBuilder.Append("--\r\n");
return signedMessageBuilder.ToString();
}
|
|
|
|
|
No, not like string.
I meant by creating needed entities like normal message.
Just sigened part is MIME_b_Multipart("multipart/signed")
and pks is MIME_bApplication("application/x-pkcs7-signature")
using System.Security.Cryptography.Pkcs;
using System.Security.Cryptography.X509Certificates;
private static void Create_ApplicationPkcs7Mime_SignedData(MIME_Entity signedEntity,MIME_Entity entityToSign,X509Certificate2 cert)
{
if(signedEntity == null){
throw new ArgumentNullException("signedEntity");
}
if(entityToSign == null){
throw new ArgumentNullException("entityToSign");
}
if(cert == null){
throw new ArgumentNullException("cert");
}
ContentInfo contentInfo = new ContentInfo(entityToSign.ToByte(null,null));
SignedCms signedCms = new SignedCms(contentInfo);
CmsSigner cmsSigner = new CmsSigner(cert);
signedCms.ComputeSignature(cmsSigner);
byte[] pkcs7Data = signedCms.Encode();
MIME_b_Application pkcs7Mime = new MIME_b_Application(MIME_MediaTypes.Application.pkcs7_mime);
signedEntity.Body = pkcs7Mime;
signedEntity.ContentType.Parameters["smime-type"] = "signed-data";
signedEntity.ContentType.Param_Name = "smime.p7m";
signedEntity.ContentDisposition = new MIME_h_ContentDisposition(MIME_DispositionTypes.Attachment);
signedEntity.ContentDisposition.Param_FileName = "smime.p7m";
pkcs7Mime.SetData(new MemoryStream(pkcs7Data),MIME_TransferEncodings.Base64);
}
modified on Friday, March 19, 2010 8:27 AM
|
|
|
|
|
Hi Ivar,
first of all thanks for this magnificent piece of code.
Could you still look at the code again, as I think I just found a small problem in the MimeEntity class.
The ParentEntity property is declared as follows:
public MimeEntity ParentEntity {
get{ return m_pParentEntity;
}
Unfortunately I can't see any code that ever initializes the private field m_pParentEntity. So I fear that the ParentEntity property will always return null.
Cheers,
kamiwa
|
|
|
|
|
Hi,
I have already said that very many times in thos forum: Get latest from:
http://www.lumisoft.ee/lswww/download/downloads/
|
|
|
|
|
Hi Ivar,
First, I'm so grateful to you for sharing your great work with all of us, this is just incredible! Its's exactly what I was looking for (actually, it's much more than that), and for beginners like me who are eager to learn, it's a great tool to understand certain things, and also an astonishing time saving: there are so much things I won't have to find out myself how to do them thanks to your class library. Many many thanks, Ivar, really.
I found your imap_client_app among the downloadable examples available on your website. I wanted to make a step by step debugging to see how you do it, so I downloaded the latest version of your Lumisoft.Net class library and then imported all the needed classes in the imap_client_app. But I encountered a few problems: there are some differences between the Lumisoft.Net DLL used in your imap_client_app dating from Nov 5 and the latest version of the Lumisoft.Net class library dating from Oct 5 (there are especially class or method naming differences), so I tried to adapt the corresponding names, but once I did that, some bugs occured (with date format or other things), which do not occur when running imap_client_app with the DLL you used with this application.
So, if you could make the Lumisoft.Net class library project corresponding to the DLL you used with imap_client_app available for download, this would very much help me and would be great!
Thanks very much for all,
Michaël
|
|
|
|
|
Hi,
Latest code is in SVN (url in readme.txt).
www zip file updated only if no pending changes, otherwise code may contain currupt classes.
|
|
|
|
|
Cool, I found everything I needed, thanks a lot!
Cheers
Michaël
|
|
|
|
|
I am parsing the raw message content that an email processing program wrote into a database column. The message starts with:
This is a multi-part message in MIME format. --_----------=_125643366138564143 Content-Disposition: inline Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="US-ASCII" MIME-Version: 1.0
When I try to parse using Mime.Parse, I get an InvalidFieldNameException in HeaderField.Name's setter. The value is "--_----------=_125643366138564143 Content-Disposition:".
Is there something wrong with the message I am processing? Am I using the library wrong?
Thanks!
Eric
|
|
|
|
|
|
After removing everything up to the first thing that looks like a correct header ("Content-Disposition: inline ..."), the email parses without throwing an Exception. However, there are no useful results in the Mime object returned by Mime.Parse.
BodyHtml and BodyText are both null.
MainEntry.Data and MainEntry.DataEncoded contain zero bytes (0x00).
Date is 1/1/0001.
MessageID, MimeVersion, ReplyTo, Sender, Subject, To are all null.
HeaderString contains the entire input message, including encoding like "= ", except that some CR LF have been inserted.
Header.Name = "Content-Disposition:";
Header.Value starts "inline Content-Transfer-Encoding: 7bit Content-Type: message/rfc822 >From My SenderName Oct 12...."
Somehow Content-Transfer-Encoding is not being recognized as a new header.
I'm sure it's something I'm doing wrong, or something that's happening to the email before it reaches me, but I'm lost as to what. By the way, I'm processing feedback loop messages from Yahoo and AOL... so I guess they create properly formatted emails.
modified on Sunday, October 25, 2009 3:47 PM
|
|
|
|
|
Probably you have some problems with CRLF in message.
Also i see you use very old version, you should try latest:
http://www.lumisoft.ee/lswww/download/downloads
|
|
|
|
|
Sir,
I like to implement a mailserver application using .Net with C# as part of my accademic project.I downloaded your mail server source code. But some of the concepts are not clear to me.Please give me a guide line to develop a mail server. i know Its not a simple task.But i can if you are help me. I am going to the end of MCA.I have knowledge in C# & ASP.My mail id is vibince@yahoo.co.in.
I am expecting for your reply.
Thanks in advance......
|
|
|
|
|
dear ivar,
in the first place thankyou for your great sourcecode
one thing i can't manage is to save the attacchment out of a message.
for example what do i wrong here to get a bytearray:
byte[] emldata = ...
Mail_Message mail = Mail_Message.ParseFromByte(emldata);
MIME_Entity miment = new MIME_Entity();
if (mail.Attachments != null)
{
for (int j = 0; j < mail.Attachments.Count(); j++)
{
MIME_b_Application attachm = new MIME_b_Application(mail.Attachments[j].Body.MediaType);
byte[] buffer = ???
}
}
many thanks in advance
|
|
|
|
|
Hi,
Tehre are:
.Data property
Or for large data
GetDataStream() method
|
|
|
|
|
Hi Thanks for this component.
Great work..
There is some problem to save attachment from eml; when there is an .eml file itself as attachment in an eml file.
|
|
|
|
|
Ehe "There is some problem", it sound like huston we have problem, what it the problem ?
|
|
|
|
|
Sorry for not providing detail.
Problem was when there was attachment type of eml.
it was returning no byte array from that attachment.
And also it was not taking some other files in that attachment.
But As I said the latest version is working fine.
Any way Good work. It's one among the top post I found in Code project.
|
|
|
|
|