GithubHelp home page GithubHelp logo

bertjohnson / opaquemail Goto Github PK

View Code? Open in Web Editor NEW
92.0 15.0 35.0 2.68 MB

.NET email library and proxy supporting IMAP, POP3, and SMTP with S/MIME and PGP.

Home Page: https://opaquemail.org

License: Other

C# 96.48% HTML 3.52%
c-sharp email imap pop3 smtp smime pgp encryption

opaquemail's Introduction

Important

As of May 2017, this project is not actively maintained. A great alternative is MailKit by jstedfast.

OpaqueMail .NET Email Library

.NET email library with full support for IMAP, POP3, and SMTP.

Supports S/MIME and PGP message signing, encryption, and decryption to foster better email security and privacy.

Follows IETF standards, implementing all IMAP4rev1, POP3, SMTP, and S/MIME 3.2 commands plus common extensions such as IDLE. Supports MIME, Unicode, and TNEF encoding.

Includes a fully-featured test client that allows browsing and searching of IMAP and POP3 messages as well as sending of SMTP messages with encryption. Automatically embeds images into Text/HTML messages and strips Script tags.

Features patterns similar to System.Net.Mail.MailMessage and System.Net.Mail.SmtpClient for simplified upgrades of existing code. Implements .NET 4.5 async and await.

Thoroughly documented. Optimized for security, usability, and performance.

Supporting documentation and tutorials available at https://github.com/bertjohnson/OpaqueMail/wiki/OpaqueMail-Library-Tutorial.

Licensed according to the MIT License (http://mit-license.org/).

Created by Bert Johnson (https://bertjohnson.com/) of Allcloud Inc. (https://allcloud.com/).

OpaqueMail Email Proxy

SMTP proxy and message transfer agent (MTA) to add or remove S/MIME message signing, encryption, and authentication for outbound messages. Can operate in passthrough mode or augment messages to add or filter headers.

Also serve as a passthrough IMAP and POP3 proxy to import S/MIME certificates, filter IPs, or export messages.

Simplifies email protection for Outlook, Thunderbird, Windows Live Mail, Opera Mail, and other email clients.

Can be used to secure and authenticate email programs that connect to SMTP servers anonymously (e.g. SharePoint).

Runs as a Windows service. Inbound and outbound IPs, ports, logging, and TLS / SSL settings are all configurable via XML.

Supporting documentation and tutorials available at https://github.com/bertjohnson/OpaqueMail/wiki/OpaqueMail-Proxy-Tutorial.

Licensed according to the MIT License (http://mit-license.org/).

Created by Bert Johnson (https://bertjohnson.com/) of Allcloud Inc. (https://allcloud.com/).

License

Copyright © 2013-2017 Bert Johnson (https://bertjohnson.com/) of Allcloud Inc. (https://allcloud.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.

opaquemail's People

Contributors

bertjohnson avatar eikonne avatar hellfirehd avatar infinity7117 avatar yannik995 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

opaquemail's Issues

'ansi_x3.110-1983' is not a supported encoding name

To resolve this issue, please have a look at
http://stackoverflow.com/questions/16044154/what-should-i-do-with-emails-using-charset-ansi-x3-110-1983

According to this page on the IANA's site, ANSI_X3.110-1983 is also known as:

iso-ir-99
CSA_T500-1983
NAPLPS
csISO99NAPLPS

Following is the exception.

Message='ansi_x3.110-1983' is not a supported encoding name.
Parameter name: name
   Source=mscorlib
   ParamName=name
   StackTrace:
        at System.Globalization.EncodingTable.internalGetCodePageFromName(String name)
        at System.Globalization.EncodingTable.GetCodePageFromName(String name)
        at System.Text.Encoding.GetEncoding(String name)
        at OpaqueMail.Net.MimePart.get_Body()
        at OpaqueMail.Net.ReadOnlyMailMessage..ctor(String messageText, ReadOnlyMailMessageProcessingFlags processingFlags, Boolean parseExtendedHeaders)
        at OpaqueMail.Net.ReadOnlyMailMessage..ctor(String messageText, ReadOnlyMailMessageProcessingFlags processingFlags)
        at OpaqueMail.Net.ImapClient.<GetMessageHelper>d__15d.MoveNext()
     --- End of stack trace from previous location where exception was thrown ---
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
        at OpaqueMail.Net.ImapClient.<GetMessagesAsync>d__a3.MoveNext()
     --- End of stack trace from previous location where exception was thrown ---
        at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
        at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
        at OpaqueMail.Net.ImapClient.<GetMessagesAsync>d__a0.MoveNext()
   InnerException: 

.GetMessages() - StartIndex is not working

I look up the last Email UID, then set that as the StartIndex. For some reason it won't go get the newer emails unless I go back like 7-10 prior to the last ID to use as the start index. Then it goes ahead and gets the IDs that are actually greater than the StartIndex.

Example: .
Dim recentMessages As List(Of ReadOnlyMailMessage) = mIMAPClient.GetMessages("Inbox", 10, intLastID, False, False, False)

I have also tried:this and find the same results:
(I have to set the starting point like 7-10 before the last ID as the starting point to get this to work).

Dim mb As Mailbox = mIMAPClient.ExamineMailbox(MailBoxName.Name)
If Not mb Is Nothing Then
For intMsg As Integer = intLastID To mb.UidNext
GetMessageByID(intMsg, MailBoxName.Name)
Next
End If

Any ideas why it won't get the recent emails without setting the StartIndex back several prior to the last ID?

By the way I am using this with VB.Net 2012 - .Net Framework 4.5

Thanks ahead of time!
Jeff

MailMessage class is not CLS compliant

Let me start off by thanking you for making this library available, it's fantastic!

I'm currently using OpaqueMail as part of a PowerShell script, and ran into a problem when trying to view the contents of MailMessage objects:

The field or property: "pgpSigned" for type: "OpaqueMail.MailMessage" differs only in letter casing from the field or property: "PgpSigned". 
The type must be Common Language Specification (CLS) compliant.
At line:1 char:1
+ $messages[0].Subject
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : NotACLSComplaintField

In C#, having public properties/fields that only differ in character casing is perfectly valid, but this is illegal other languages like VB or PowerShell.

The offending line is highlighted here:

public bool pgpSigned = false;

I'm not opening a PR because the fix is trivial: just make pgpSigned private. pgpEncrypted also looks like it was meant to be private.

Lastly, a workaround for anyone else experiencing this issue:

Function Get-MailMessageProperty
{
    Param(
        [Parameter(Mandatory = $true)] [OpaqueMail.MailMessage] $MailMessage,
        [Parameter(Mandatory = $true)] [string] $Property
    )
    return [OpaqueMail.MailMessage].GetProperty($Property).GetValue($MailMessage)
}

To get the message subject for example, call the function like this:

Get-MailMessageProperty $mailMessageObject -Property Subject

Digital signature invalid on Outlook 2017

Hello. We are testing OpaqueMail proxy and we have encountered a problem when we send an email with Content-Type: multipart/alternative.
using Outlook 2016 as client, when we receive an email it shows a problem with the signature. The detail of the error is: The message contents may have been altered. Signed by [email protected] using RSA/SHA1.
If we send a simple email, everything works fine but with multipart/alternative, digital signature fails.
The body of the message received is:
`From: [email protected]
To: [email protected]
Subject: TEST
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="OpaqueMail-boundary"
Content-Transfer-Encoding: 7bit

--OpaqueMail-boundary
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

TEST
--OpaqueMail-boundary
Content-Type: text/html
Content-Transfer-Encoding: 7bit

TEST
--OpaqueMail-boundary--
`
we have modified OpaqueMail.TestClient to generate multipart/alternative email. If we sign email directly with TestClient without pass through OpaqueMail Proxy all works fine.

Parsing of boundary parameter is broken

string boundaryName = Functions.ReturnBetween(contentType, "boundary="", """);
if (boundaryName.Length < 1)
{
cursor = contentType.IndexOf("boundary=", StringComparison.OrdinalIgnoreCase);
if (cursor > -1)
boundaryName = contentType.Substring(cursor + 9);
cursor = boundaryName.IndexOf(";");
if (cursor > -1)
boundaryName = boundaryName.Substring(0, cursor);
}

LWSP can appear between the boundary string and the '=', it can also appear between the '=' and the boundary value. It can also appear after the boundary value before the ';'.

Your parser also doesn't handle rfc2184/rfc2231 encoding of parameters.

Bug in MapiProperties in TnefEncoding.cs

Hi,

i found out that when the variable "propertyValueCount" > 1 the decoding of tnef file fails and no body is found. I managed to get it to work with the following fix:

(line 279)
// If there are multiple properties, read how many.
uint propertyValueCount = 1;
if (isPropertyMultiValue)
propertyValueCount = ReadUint32(MapiPropertiesBytes);

// Process only MAPI property types we care about.
for(int j = 0; j < propertyValueCount; j++) // !!!!!!!! i added this
switch (propertyType)
{

bug can be reproduced with file winmail_2.dat from the following link:

sourceforge.net/p/tnef/bugs/_discuss/thread/57b3fb94/aff8/attachment/Sample%20Winmails.7z

Deleting PoP3 mails by UID

Using pop3client.DeleteMessage(string) (where string means the UID) doesn't work. I checked the internal implementation and it is rather suspicious that it works exactly like DeleteMessage(int) (where int means the message index).

As per POP3 protocol specification, DELE command accepts the message number (the index) as a parameter so calling the same command with UID can hardly do the same.
(and my few test confirm my doubts... - messages are not deleted)

Content-Type: application/pdf;

Hello,

Another type of attachment issue I've come across is where the Content-Type is an application not a boundary
example:
Content-Type: application/pdf;\r\n name="Payment Advice Note from 05/03/2017.pdf

This does not set a MimeBoundaryName in the MailMessage.MailMessage(...) so it does not process the attached PDF properly.

Instead the email looks something like

%PDF-1.3
%����
%RSTXPDF3 Parameters: DRSTXbdh
%Devtype PDF1 Font TIMES bold Lang EN Script: 0 ->/C001
2 0 obj
<<
/Type /FontDescriptor
/Ascent 683
/CapHeight 676
/Descent -217
/Flags 34
/FontBBox [-168 -218 1000 935]
/FontName /Times-Bold
/ItalicAngle 0
/StemV 105

endobj
3 0 obj
/WinAnsiEncoding
endobj
4 0 obj
<<
/Type /Font
/Subtype /Type1
/BaseFont /Times-Bold
/Name /C001
/Encoding 3 0 R
/Widths
[ 0250 0333 0554 0500 0500 1000 0833 0333 0333 0333 0500 0571 0250 0333 0250 0279 0500 0500 0500 0500 0500 0500 0500 0500 0500 0500 0333 0333 0571 0571 0571 0500 0929 0721 0667 0721 0721 0667 0613 0779 0779 0388 0500 0779 0667 0946 0721 0779 0613 0779
0721 0554 0667 0721 0721 1000 0721 0721 0667 0333 0279 0333 0579 0500 0333 0500 0554 0446 0554 0446 0333 0500 0554 0279 0333 0554 0279 0833 0554 0500 0554 0554 0446 0388 0333 0554 0500 0721 0500 0500 0446 0396 0221 0396 0521]
/FirstChar 32
/LastChar 126
/FontDescriptor 2 0 R

endobj
%Devtype PDF1 Font TIMES normal Lang EN Script: 0 ->/C002
5 0 obj
<<
/Type /FontDescriptor
/Ascent 683
/CapHeight 662
/Descent -217
/Flags 34
/FontBBox [-168 -218 1000 898]
/FontName /Times-Roman
/ItalicAngle 0
/StemV 105

endobj
6 0 obj
<<
/Type /Font
/Subtype /Type1
/BaseFont /Times-Roman
/Name /C002
/Encoding 3 0 R
/Widths
[ 0250 0333 0408 0500 0500 0833 0779 0333 0333 0333 0500 0563 0250 0333 0250 0279 0500 0500 0500 0500 0500 0500 0500 0500 0500 0500 0279 0279 0563 0563 0563 0446 0921 0721 0667 0667 0721 0613 0554 0721 0721 0333 0388 0721 0613 0888 0721 0721 0554 0721
0667 0554 0613 0721 0721 0946 0721 0721 0613 0333 0279 0333 0471 0500 0333 0446 0500 0446 0500 0446 0333 0500 0500 0279 0279 0500 0279 0779 0500 0500 0500 0500 0333 0388 0279 0500 0500 0721 0500 0500 0446 0479 0200 0479 0542]
/FirstChar 32
/LastChar 126
/FontDescriptor 5 0 R

endobj
%Devtype PDF1 Font HELVE normal Lang EN Script: 0 ->/C003
7 0 obj
<<
/Type /FontDescriptor
/Ascent 718
/CapHeight 718
/Descent -207
/Flags 32
/FontBBox [-166 -225 1000 931]
/FontName /Helvetica
/ItalicAngle 0
/StemV 105

endobj
8 0 obj
<<
/Type /Font
/Subtype /Type1
/BaseFont /Helvetica
/Name /C003
/Encoding 3 0 R
/Widths
[ 0279 0279 0354 0554 0554 0888 0667 0221 0333 0333 0388 0583 0279 0333 0279 0279 0554 0554 0554 0554 0554 0554 0554 0554 0554 0554 0279 0279 0583 0583 0583 0554 1017 0667 0667 0721 0721 0667 0613 0779 0721 0279 0500 0667 0554 0833 0721 0779 0667 0779
0721 0667 0613 0721 0667 0946 0667 0667 0613 0279 0279 0279 0471 0554 0221 0554 0554 0500 0554 0554 0279 0554 0554 0221 0221 0500 0221 0833 0554 0554 0554 0554 0333 0500 0279 0554 0500 0721 0500 0500 0500 0333 0258 0333 0583]
/FirstChar 32
/LastChar 126
/FontDescriptor 7 0 R

endobj
9 0 obj
<<
/Length 10 0 R

stream
q 1 g 0 g 0.50 w 28.35 175.70 510.25 425.20 re S Q q 1 g 0 g 0.50 w 226.80 175.70 0.00 425.20 re S Q q 1 g 0 g 0.50 w 396.85 175.70 0.00 425.20 re S Q q 1 g 0 g 0.50 w 28.
....
startxref
8079
%%EOF

Any thoughts?

Thank you.

GetMessageHelper() seekStart and seekEnd won't work

While trying to help someone fix another issue reported in GetMessageHelper(), I noticed that it takes a seekStart and seekEnd.

These parameters allow fetching a substream of the message but GetMessageHelper returns a MailMessage and later in the code, it attempts to parse the substream as a MailMessage.

This won't be doable if I attempt to fetch a substream range that does not include the headers.

error while using the ImapClient.GetMessages() method,

each time I try to use the method I have an error specifying that the input string is in an incorrect format, the first time I've used the named parameters to resolve the issue, but just after some test I found that the problem persist and, whether i'm using any of the overloads of the method I still have the same message error,

var mails = _client.GetMessages(folderName, 30, 0, false, false, false);

it was correctly working before,

Cannot be used with strong-named assemblies

I was reviewing OpaqueMail to use in an existing project. The project happens to run in an environment (Component Services, a.k.a. COM+) that requires all assemblies, including any referenced assemblies, to have a strong name. The NuGet package does not include a strong-named DLL, so it cannot be used in this environment.

We will try building from source and using our own key, but it would be easier to use if the project included an assembly with a strong name.

Timeout on ImapClient.Connect

When attempting to connect with ImapClient.Connect and SSL set to false the connection will hang indefinitely. No exception is thrown.

I attempted to connect to outlook.office365.com, port 993 with a wrong username and password to provoke an exception, but nothing happens. It just hangs.

It would be useful to have the possibility to configure a timeout aswell as have an exception thrown if a connection cannot be established.

Very slow performance

Why sending directly to SMTP (mailgun) is like 2 secound but proxing via OpaqueMail to Mailgun is like 15 seconds.

My config:
http://prntscr.com/ek1njm

Here is one log where timespan is 30 secounds to forward.
[3/14/2017 11:13:50 PM] 310f182d-7537-48df-ae78-d4f757b4ca92 2 VERBOSE Forwarding message from {xxxx} with subject {WP Mail SMTP: Test mail to [email protected]} and size of {423}. [3/14/2017 11:14:20 PM] 310f182d-7537-48df-ae78-d4f757b4ca92 2 RAW C: Date: Tue, 14 Mar 2017 23:13:50 +0000

Also when i restart the service i`m always getting error:

CRITICAL Exception when starting proxy: A blocking operation was interrupted by a call to WSACancelBlockingCall

Then i need to do like STOP -> WAIT -> START the service.

Any suggestion?

using CERTCLIENTLib;

For whatever reason, when I downloaded this to compile it myself, I needed to change using CERTCLILib; to using CERTCLIENTLib; in CertHelper.cs

IdleFrequency should not exist

When we enter the IDLE state, the server stream should be read in real-time. Having to wait for the idle timer to expire kinda defeats the purpose of IDLE for me.

Just a general Question about OpaqueMail vs MailKit

I have seen MailKit mentioned in at least one other issue, so I was wondering more about the differences between MailKit and OpaqueMail, and what is the purpose or goal of OpaqueMail. More or less, why should anyone use OpaqueMail over MailKit. Looking at the initial code page, it seems Mailkit has more features, but it may just be a high level explanation over a more detailed explanation.

Problem with UniqueCommandTag

You have a Problem with the UniqueCommandTag(). Here you only add 1 to a number.
So then in ReadDataAsync(string commandTag, string previousCommand, int timeout = 0)
there is one IF-Statment (if (responseParts[0] == commandTag || (...)) that asks, if the first part is equal to the commandTag. If so you can't get the complete mail.
E.g.:
CommangTag = 4
response = "4 or 5 times"
responseParts[0] = "4"

I solved this problem like this:

        public string UniqueCommandTag()
        {
            return (++CommandTagCounter).ToString() + "~#~OPAQUE-MAIL~#~";
        }

I hope you understand this.

Best regards

Butch0r

html template support?

Hey,OpaueMail is great.If i want to send an email which is html format,and it has pictures(not attachment) like edm.I mean pictures insert as resources,not like ,is that supported?

AsMailMessage not working?!

Hello,
I want to read a .eml file, and then to send it over smtp.
This is my code.
void SendMessage()
{
ReadOnlyMailMessage loadedMessage = ReadOnlyMailMessage.LoadFile("eml.eml");

        SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);
        smtpClient.Credentials = new System.Net.NetworkCredential("[email protected]", "yyy");
        smtpClient.EnableSsl = true;

        MailMessage message = new MailMessage();
        message = loadedMessage.AsMailMessage();

        message.To.Clear();
        message.From = new System.Net.Mail.MailAddress("[email protected]");
        message.To.Add("[email protected]");

        smtpClient.SendAsync(message);

        MessageBox.Show("Trimis");
    }

After: message = loadedMessage.AsMailMessage();
I get
-Size 'message.Size' threw an exception of type 'System.ObjectDisposedException' long {System.ObjectDisposedException}

base {System.ObjectDisposedException: Cannot access a closed Stream.
at System.IO.__Error.StreamIsClosed()
at System.IO.MemoryStream.get_Length()
at OpaqueMail.Net.MailMessage.get_Size()} System.InvalidOperationException {System.ObjectDisposedException}

Message: "Cannot access a closed Stream." string

What am I doing wrong?

Regards.

.GetMessages() - Index and length must refer to a location within the string.\r\nParameter name: length

Hi, I was using the code in the tutorials with my gmail mail box and I got this error:
Index and length must refer to a location within the string.\r\nParameter name: length

Here is the code where I get the error:
List recentMessages = await imapClient.GetMessagesAsync("Inbox", 50);

Here is some more info:
at System.String.Substring(Int32 startIndex, Int32 length)
at OpaqueMail.ImapClient.d__190.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at OpaqueMail.ImapClient.d__151.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at OpaqueMail.ImapClient.d__148.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

When I try to get 2 mails instead of 50 everything is OK. I guess there is an email that is breaking the code. Maybe the problem is in the body of the email, because when I set headersOnly = true, no exception is thrown.

Missing dependencies?

When I tried a build of 035355f I got loads of missing dependency errors:

Error 1 The type or namespace name 'CERTCLILib' could not be found (are you missing a using directive or an assembly reference?) C:\Projects\C#\OpaqueMail\OpaqueMail.Net.CertHelper\CertHelper.cs 17 7 OpaqueMail.Net.CertHelper
Error 2 Metadata file 'C:\Projects\C#\OpaqueMail\OpaqueMail.Net.CertHelper\bin\Debug\OpaqueMail.Net.CertHelper.dll' could not be found C:\Projects\C#\OpaqueMail\OpaqueMail.Proxy\CSC OpaqueMail.Proxy
Error 3 Metadata file 'C:\Projects\C#\OpaqueMail\OpaqueMail.Net.CertHelper\bin\Debug\OpaqueMail.Net.CertHelper.dll' could not be found C:\Projects\C#\OpaqueMail\OpaqueMail.Net.TestClient\CSC OpaqueMail.Net.TestClient
Error 4 Metadata file 'C:\Projects\C#\OpaqueMail\OpaqueMail.Net.CertHelper\bin\Debug\OpaqueMail.Net.CertHelper.dll' could not be found C:\Projects\C#\OpaqueMail\OpaqueMail.ProxyService\CSC OpaqueMail.ProxyService
Error 5 Metadata file 'C:\Projects\C#\OpaqueMail\OpaqueMail.Proxy\bin\Debug\OpaqueMail.Proxy.dll' could not be found C:\Projects\C#\OpaqueMail\OpaqueMail.ProxyService\CSC OpaqueMail.ProxyService
Error 6 Metadata file 'C:\Projects\C#\OpaqueMail\OpaqueMail.Net.CertHelper\bin\Debug\OpaqueMail.Net.CertHelper.dll' could not be found C:\Projects\C#\OpaqueMail\OpaqueMail.ProxySettings\CSC OpaqueMail.ProxySettings
Error 7 Metadata file 'C:\Projects\C#\OpaqueMail\OpaqueMail.Proxy\bin\Debug\OpaqueMail.Proxy.dll' could not be found C:\Projects\C#\OpaqueMail\OpaqueMail.ProxySettings\CSC OpaqueMail.ProxySettings
Error 8 Metadata file 'C:\Projects\C#\OpaqueMail\OpaqueMail.ProxyService\bin\Debug\OpaqueMail.ProxyService.exe' could not be found C:\Projects\C#\OpaqueMail\OpaqueMail.ProxySettings\CSC OpaqueMail.ProxySettings

Failing generating certificate.

When starting the service it failes with an COM-exception (Windows Server 2012 R2 64bit):

[17-6-2016 16:05:31] 8b20419a-7842-4915-8e26-ed379cc0bfe3
WARNING No signing certificate found, so generating new certificate.
[17-6-2016 16:05:31] 8b20419a-7842-4915-8e26-ed379cc0bfe3
CRITICAL Exception when starting proxy: Unable to cast COM object of type 'System.__ComObject' to interface type 'CERTENROLLLib.CX509PrivateKey'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{728AB362-217D-11DA-B2A4-000E7BBB2B09}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Any idea's? Is this a bug or environmental?

Base64 encoded attachment filenames

In pursuit of better integration with commercial doc scanners:

Change MimePart.cs line 91:

Name = name;

to:

Name = Functions.DecodeMailHeader(name).Replace("\r","").Replace("\n","");

Aaaaaaaaaaaaaaand you're welcome, again.

OpaqueMail not processing PDF attachments from Toshiba/old scanner

Thought I'd share the answer to this problem for posterity and positive karma. I fixed this by changing ReadOnlyMailMessage.cs Line 162

string[] headerParts = new string[] { header.Substring(0, colonPos), header.Substring(colonPos + 2) };

to

string[] headerParts = new string[] { header.Substring(0, colonPos), header.Substring(colonPos + 1).TrimStart(new char[] { ' ' }) };

to match how it's done in MimePart.cs Line 586

Apparently, some poorly engineered scanners craft the mail message without a space after the semicolon in the headers:

Content-Type:Multipart/mixed;boundary="TTECe69930ef-29c1-4186-b653-0186ee31a29c"

Should be:

Content-Type: Multipart/mixed;boundary="TTECe69930ef-29c1-4186-b653-0186ee31a29c"

Aaaaaaaaaaaaaaaaaaaaand you're welcome

Boundary with a capital B is not supported

I have had a few emails coming in with attachments that have had issues and cause the OpaqueMail to not handle the exception.

One I found is in MailMessage.cs around line 424 looking at "content-type"
MimeBoundaryName = Function.ExtractMimeParameter(ContentType, "boundary")

if instead inside is Boundary it throws an unhandled exception.

So you might alter the
Functions.ExtractMimeParameter(...)
from
int parameterPos = mimeHeader.IndexOf(mimeParameter);
to
int parameterPos = mimeHeader.ToLower().IndexOf(mimeParameter.ToLower());

This fixed this issue for me.
Thanks again for all your efforts on this project.

Code that locates boundaries is broken

int boundaryEnd = body.IndexOf("\r\n--" + boundaryName, mimeStartPosition, StringComparison.OrdinalIgnoreCase);

There are several issues here...

  1. OrdinalIgnoreCase is just plain wrong.
  2. If you have a boundary of "x" and you find a line that begins with "--x", that is not enough to assume that it is the boundary you are looking for. What if the line you actually found is "--xyz"? or what if it's "--xander"?

bug in DecompressRTF (TnefEncoding.cs)

Hi,

i found out the value of variable:

string rtfPreBufferString = "{\rtf1\ansi\mac\deff0\deftab720{\fonttbl;}{\f0\fnil \froman \fswiss \fmodern \fscript \fdecor MS Sans SerifSymbolArialTimes New RomanCourier{\colortbl\red0\green0\blue0\n\r\par \pard\plain\f0\fs20\b\i\u\tab\tx";

is wrong, based on documentation for RTF (link) the sequence should contain CRLF sequence, which is \r\n not \n\r like in your variable

i found this while i was coding tnef parser based on your implementation in c++. This causes that the newlines are broken in the RTF body string. (empty lines are added to the string when viewed under debugger).

It probably isn't a big issue, i just thought you might care :)

http://www.google.sk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&ved=0CC4QFjAB&url=http%3A%2F%2Fdownload.microsoft.com%2Fdownload%2F5%2FD%2FD%2F5DD33FDF-91F5-496D-9884-0A0B0EE698BB%2F%5BMS-OXRTFCP%5D.pdf&ei=anBeUrTmE8fPsgaPwIC4Dw&usg=AFQjCNENgk1bu0jgIz-XX_hIetFOCCt5jg&bvm=bv.54176721,d.Yms

Pop3Client.LogOut() leaves client in borked state

If I explicitly call LogOut() on a Pop3Client, at least some mail servers will close the connection. (I'm currently testing with hMailServer.) Then when the client gets disposed, LogOut() gets called again, and the following ReadData() throws an IOException.

I'm not sure what the best fix is – maybe LogOut() should clean up after itself better so that Dispose() knows that the client is already disconnected?

Error on some retrievals

Hello,

This code has been create. I really appreciate the work you've put into it. Thanks :)

I found what seems to be an error/issue in the code. I was getting an error message "Index and Length must refer to a location within the string."

After running several tests and stepping through the code I found the following:
OpaqueMail.ImapCLient.GetMessageParialHelper()
line 2391
response = response.Substring(lineBreak + 2, bodyLength);
this was trying to get a substring returned longer than the message.
In my case, pulling an email from gmail,

  • the linebreak was 36 (+2) so 38
  • response.Length = 6979
  • bodylength returned 6954
    So that equaled 6992 and returned an error.

So a possible alteration could be (at least this is what I did, but I'd love to hear what you would do)

(OLD)
if (bodyLength > 0)
response = response.Substring(lineBreak + 2, bodyLength);
else
{
response = response.Substring(response.IndexOf("\r\n") + 2);
response = response.Substring(0, response.Length - 2);
}

(NEW)
if (bodyLength > 0)
if (response.Length < bodyLength + lineBreak + 2)
{
response = response.Substring(lineBreak + 2);
}
else
{
response = response.Substring(lineBreak + 2, bodyLength);
}
else
{
response = response.Substring(response.IndexOf("\r\n") + 2);
response = response.Substring(0, response.Length - 2);
}

Internal CA?

I am trying to send a mail through a smtp server whose ssl certificate is bound to the main domain, and not the "smtp.theserver.com" smtp service.

I have trouble getting past the exception for bad certificate. Is there any way I could "whitelist" this specific certificate?

Wrong variable is returned in MailMessage.Size

In class OpaqueMail.MailMessage, property Size, the estimated size is correctly calculated (size of body + size of all attachments) but not returned.

old: return Body.Length;
new: return size;

SecureString support?

Microsoft has implemented the SecureString class in an effort to provide better security with sensitive information (like credit cards, passwords, etc.). It automatically provides:

  • encryption (in case of memory dumps or page caching)
  • pinning in memory
  • ability to mark as read-only (to prevent any further modifications)
  • safe construction by NOT allowing a constant string to be passed in

Could this be useful for password handling in OpaqueMail? Obviously the old constructors that accept a normal string should remain for compatibility.

"Start index cannot be less than zero" error while sending Unicode subject via SMTP

Hi,
both your test platform and my code return this error while sending Smtp with a Unicode subject,

the subject sample that causes error:

یک بروزرسانی در نرم افزار سامانه پایش آب ایران (IWMS) توسط سعید ایجاد شد.

my code:

SmtpClient smtpClient = new SmtpClient(ServerSettings.SMTPHost, 587);
            smtpClient.Credentials = new  NetworkCredential(ServerSettings.SMTPUsername, ServerSettings.SMTPPassword);
            smtpClient.EnableSsl = true;

            MailMessage message = new MailMessage(item.FromAddress, item.ToAddress, item.MailSubject, item.Body);
            message.IsBodyHtml = true;
            message.SubjectEncoding = Encoding.Unicode;

            try
            {
                await smtpClient.SendAsync(message);
            }
            catch
            {
                return false;
            }

Wrong TNEF-Attachment Title

Hello,

at first, thanks for your great work!
I'm trying to extract an attachment from an TNEF winmail.dat.
This works great but it seems there is a wrong file name.

Here a short snipping from the winmail.dat content (in a editor):
tnef_att_title

Your code (MimePart.Name) extracts the filename ".PDF File.pdf".
The correct filename (like Outlook or Thunderbird with extension reads it) is "BST204DE.pdf".

Is there an easy way to get the correct filename?

Chinese characters become garbled after signing.

I tried to use MailMessage class to create a signed email.
This mail contains Chinese characters in the subject and body, and they become garbled after signing.
I set the values of SubjectEncoding and BodyEncoding, but they don't work and the characters are still garbled.
If I don't sign this mail, it doesn't happen.
How can I do to solve this problem?
Thanks.

fix for bad pop 3 server response

pop3 server responds with first line empty to "UIDL\r\n"

actual reply:
\n1 1490184700.13481.s1.xxx.xxx.xx,S=701\n2 1490184832.13551.s1.xxx.xxx.xx,S=701\n3 1490186235.14276.s1.xxx.xxx.xx,S=11843

interpreted reply:
{string[4]}
[0]: ""
[1]: "1 1490184700.13481.s1.xxx.xxx.xx,S=701"
[2]: "2 1490184832.13551.s1.xxx.xxx.xx,S=701"
[3]: "3 1490186235.14276.s1.xxx.xxx.xx,S=11843"

The first empty string causes an exeption in the next foreach loop, at Pop3Client.cs, line 658.

Recomend fix the above line 653
string[] responseLines = response.Split('\n');
with
string[] responseLines = response.Split('\n').Where(w => !string.IsNullOrEmpty(w)).ToArray()

or similar :D

EDIT

sorry for posting here as an issue, but direct editing the file did not work for me at the time.
now it did, i submitted the change

Modify CertHelper FindBySerialNumber to FindByThumbprint

Thumbprints are more easily able to uniquely identify the certificate to use. I could have multiple certificates loaded with serial number collisions (they're only unique to the CA that issued them) or have duplicate subject names (it's useful to have multiple certs for different purposes for reasons like Key Escrow, etc.)

Thumbprint is a MUCH safer way to identify a certificate uniquely.

multipart mime with 2 HTML Sections

I appreciate the work you do to keep this up to date.

I've been receiving a few multipart mime files where there are 2 Content-Type: text/html sections

The code in
MailMessages.ProcessMimeParts()

approx line1277 (See below)
overwrites the 1st HTML section with the second. I don't know why these email are coming from people with this double HTML section, but they are. So in testing it, I think it needs to be more something like

                    if (Body.ToUpper().StartsWith("<HTML"))
                    {
                        Body = Body + mimePart.Body;
                    }
                    else
                    {
                        Body = mimePart.Body;
                    }

I have some sample emails I could send you to test yourself if you'd like, and a better solution than this would be great too.

Thank you.

            else
            {
                // If the current body isn't text/html and this is, replace the default body with the current MIME part.
                if (!ContentType.ToUpper().StartsWith("TEXT/HTML") && contentTypeToUpper.StartsWith("TEXT/HTML"))
                {
                    // Add the previous default body as an alternate view.
                    MemoryStream alternateViewStream = new MemoryStream(Encoding.UTF8.GetBytes(Body));
                    AlternateView alternateView = new AlternateView(alternateViewStream, BodyContentType);
                    if (BodyTransferEncoding != TransferEncoding.Unknown)
                        alternateView.TransferEncoding = BodyTransferEncoding;
                    AlternateViews.Add(alternateView);

                    IsBodyHtml = true;
                    Body = mimePart.Body;
                    BodyContentType = mimePart.ContentType;
                    CharSet = mimePart.CharSet;
                }
                else
                {
                    // If the MIME part isn't of type text/*, treat is as an attachment.
                    MemoryStream attachmentStream = new MemoryStream(mimePart.BodyBytes);
                    Attachment attachment;
                    if (mimePart.ContentType.IndexOf("/") > -1)
                        attachment = new Attachment(attachmentStream, mimePart.Name, mimePart.ContentType);
                    else
                        attachment = new Attachment(attachmentStream, mimePart.Name);
                    attachment.ContentId = mimePart.ContentID;
                    Attachments.Add(attachment);
                }
            }

OpaqueMail Test Client not working with IMAP Office365 connection

I have an Office365 account that I cannot get the IMAPClient to work with. It is able to connect and see the folders, but it won't download messages. I can reproduce the behavior in the OpaqueMail test client, so I'm fairly sure it's not something I'm doing in my code. Any thoughts on how to proceed? Have you verified the OpaqueMail test client works using IMAP to an Office365 account?

Missing source files

Looks like a great package, but unfortunately at least the program.cs files in the ProxyService- and ProxySettings-projects are missing.
Could you please be so kind and add them.

email message returning null on 1st call.

Hello again.

Ran into another odd issue. Had a user have another problem getting an email. Had them forward it to me and I too saw the issue with the forwarded email.

When using the Async methods it returns a null message (imapClient.GetMessagePartialHelper line 2384
response = await ReadDataAsync(commandTag, "FETCH"); returns "0 obj " not anything containing rn so it return null.

In the Form1.ImapMessageList_SelectedIndexChanged( ) if I put an if in If (message == null)) I can try again

if (message == null)
{
//try again
// Resume idling.
await myImapClient.IdleStartAsync();

                                // Stop idling to resume commands.
                                if (myImapClient.IsIdle)
                                    await myImapClient.IdleStopAsync();

and rerun the logic
and it works fine.

I however can not seem to do this if run the non-async methods.

Any thoughts on how it can be pulled not as null or make a similar non-async process work like the above. I can try sending you the email.

(I don't know how this one person keeps getting legit businesses sending these odd email formats)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.