C# Imap search command with special characters like á,é - c#

I'm working on an imap client search function.
I use this command: UID SEARCH FROM PÉTER
When I run this command i get the following error:
Error in IMAP command UID SEARCH: 8bit data in atom
I get this error when my pattern string(for example PÉTER) contains accentuated character.
What is the solution? What sholud I do?
Edit:
I try with UTF-8 encoded string (UID SEARCH FROM PÉTER), it runs without error, but it doesn't give back any result.
I check the test email account, and there are many mails with this sender.

In IMAP you need to send 8-bit data as string literals.
Literal syntax:
{byte_count} CRLF number-of-bytes
Example search:
cmdTag SEARCH charset UTF-8 subject {4} CRLF test CRLF

Related

Is Lotus notes email client unable to render <br > tag?

I have a weird problem with Lotus Notes 8.5. In my project I am sending meeting invitation to the user. for that, I generate .ics file. Here is how i generate .ics file
var body = "Dear Raj, \n\n How are you? line break is not working \n\n how?";
using (TextWriter writer = File.CreateText("../test.ics"))
{
writer.WriteLine("BEGIN:VCALENDAR");
writer.WriteLine("PRODID:-//Microsoft Corporation//Outlook 11.0 MIMEDIR//EN");
writer.WriteLine("VERSION:2.0");
writer.WriteLine("METHOD:REQUEST");
writer.WriteLine("BEGIN:VEVENT");
writer.WriteLine("ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:participant#company.com");
writer.WriteLine("ORGANIZER;CN="Organizer":MAILTO:organizer#test.ccc");
writer.WriteLine("(DTSTART:20141231T010000Z");
writer.WriteLine("DTEND:20141231T010000Z");
writer.WriteLine("TRANSP:OPAQUE");
writer.WriteLine("SEQUENCE:0");
writer.WriteLine("UID:Company-interview-123");
writer.WriteLine("DTSTAMP:20141223T232322Z");
writer.WriteLine("SUMMARY:Interview Scheduled for Job");
writer.WriteLine("DESCRIPTION:{0}", body.Replace("\n","<br />"));
//Adding below property actually fixed the issue.
writer.WriteLine("X-ALT-DESC;FMTTYPE=text/html:{0}", body.Replace("\n","<br />"));
writer.WriteLine("LOCATION:Test Location");
writer.WriteLine("PRIORITY:5");
writer.WriteLine("X-MICROSOFT-CDO-IMPORTANCE:1");
writer.WriteLine("CLASS:PUBLIC");
writer.WriteLine("BEGIN:VALARM");
writer.WriteLine("TRIGGER:-PT15M");
writer.WriteLine("ACTION:DISPLAY");
writer.WriteLine("DESCRIPTION:Reminder");
writer.WriteLine("END:VALARM");
writer.WriteLine("END:VEVENT");
writer.WriteLine("END:VCALENDAR");
}
But Lotus email client is displaying the content as such.
its showing
Dear Raj, <br><br> How are you? line break is not working <br><br> how?
On all other email clients, my content is displaying as
Dear Raj,
How are you? line break is not working
how?
Am i missing something here?
Updated my .ics generation code to add X-ALT-DESC;FMTTYPE=text/html: to fix the issue
I just checked with a vcard that contains your Text in Lotus Notes 8.5 and IBM Notes 9, and it worked exactly as expected. BUT: It worked with your "original" Text without the replace. In the RFC2445 it states, that Line- Breaks have to be encoded as \n:
An intentional formatted text line break MUST only be included in a
"TEXT" property value by representing the line break with the
character sequence of BACKSLASH (US-ASCII decimal 92), followed by a
LATIN SMALL LETTER N (US-ASCII decimal 110) or a LATIN CAPITAL LETTER
N (US-ASCII decimal 78), that is "\n" or "\N".
That means: use
writer.WriteLine("DESCRIPTION:{0}", body);
instead of
writer.WriteLine("DESCRIPTION:{0}", body.Replace("\n","<br>"));
And your problem should be solved
The DESCRIPTION property is not meant to contain any rich text/html content but only plain text.
Lotus Notes may use some other property (X- property) to convey rich text description. Or it may use an ALTREP parameter on the DESCRIPTION, that point to another MIME bodypart in the invitation. See https://www.rfc-editor.org/rfc/rfc5545#section-3.2.1
So what you probably want to do is to send an invitation containing rich text from Lotus Notes to some external account, and then see what the MIME message that you receive looks like.

parsing base64 blob from tool output

I have a problem parsing base64 encoded blob from tool output.
I'm using this regex in c#: #"(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)"
Everything worked fine until the blob I receive looks like following (it does not have even one '='. according to wiki base64 string can have 0-2 "=" signs in the end/)
I cannot work with string before and after the blob because it can be muli-language
Provisioning the computer account... Successfully provisioned
[user-1009-1-] in the domain [testauto.sof]. Provisioning data was
saved successfully to
[C:\Users\user1\AppData\Local\Temp\user-1009-1-.blob]. Provisioning
string (2624l bytes):
ARAIAMzMzMzIAwAAAAAAAAAAAgABAAAAAQAAAAQAAgABAAAAAQAAAKADAAAIAAIAoAMAAAEQCADMzMzMkAMAAAAAAAAAAAIABAACAAgAAgAMAAIAFAAWABAAAgAcAB4AFAACABwAHgAYAAIA5pXFb5WfaEeEDMNZ4eUJVxwAAgAgAAIAJAACAAEAAADmlcVvlZ9oR4QMw1nh5QlXKAACACwAAgD8MQDgMAACADQAAgACAAAADwAAAAAAAAAPAAAAbQBpAHIAYQBnAGUAYQB1AHQAbwAuAHMAbwBmAAAAAAAQAAAAAAAAABAAAAB4AGkAcwBoAGUAbgBnAC0AMQAwADAAOQAtADEALQAAAHkAAAAAAAAAeQAAAF0APwAjAHkAWgBYADoAdwBgAGUANgB2AG8AJQBuAHkAIwBUAE4ALAAxAHUAOQBkAD4AdwA5AG8AaABgAHEAIwBhADYALABwAF0ALwBoAEgAIABqAHMATwA5AGwATgB5ADEAVQAhAE4ASwAiAEUAPQA8AGIAZQBAAC8ARgA1AGIAQAAiAG8AUgA6AGIAawAzAF4AVwBrACYATQA5AE8AdQBvAHYAZQA0AGMAKwBDAHMAUABrAGsAdQBAAF4AYAAgAFsAJQBgAGUAJwAuAG8AOwBBACgATQBuACIARgAlAG0ASwA1ADMAbQBJAHcAXQBkAAAAAAALAAAAAAAAAAoAAABNAEkAUgBBAEcARQBBAFUAVABPAA8AAAAAAAAADgAAAG0AaQByAGEAZwBlAGEAdQB0AG8ALgBzAG8AZgAPAAAAAAAAAA4AAABtAGkAcgBhAGcAZQBhAHUAdABvAC4AcwBvAGYABAAAAAEEAAAAAAAFFQAAAN0GKLrAxnxUyKGAThoAAAAAAAAAGgAAAFwAXABTAE8ARgAtAFEAQQAwADIALgBtAGkAcgBhAGcAZQBhAHUAdABvAC4AcwBvAGYAAAANAAAAAAAAAA0AAABcAFwAMQAwAC4AMgAzAC4ANwAyAC4AMgAAAAAADwAAAAAAAAAPAAAAbQBpAHIAYQBnAGUAYQB1AHQAbwAuAHMAbwBmAAAAAAAPAAAAAAAAAA8AAABtAGkAcgBhAGcAZQBhAHUAdABvAC4AcwBvAGYAAAAAABgAAAAAAAAAGAAAAEQAZQBmAGEAdQBsAHQALQBGAGkAcgBzAHQALQBTAGkAdABlAC0ATgBhAG0AZQAAABgAAAAAAAAAGAAAAEQAZQBmAGEAdQBsAHQALQBGAGkAcgBzAHQALQBTAGkAdABlAC0ATgBhAG0AZQAAAAAAAAAAAAAA
Computer account provisioning completed successfully. The operation
completed successfully.
Anyone can help me to fix the regex?
Here is regex calculator that I using:
http://regex101.com/r/wP3kP9/1
The following should work successfully:
^(?!$)(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$
regex101
In my understanding, if no = is present, it's because the string length is a multiple of 4.
I also anchored it with ^...$and used the m option so only your base64 string matches. I added (?!$) so empty lines don't match (couldn't simply change the * to + because you may want to match short strings like aa==).

A socket message from Python to C# comes through garbled

I'm trying to set up a very basic ZeroMQ-based socket link between Python server and C# client using simplejson and Json.NET.
I try to send a dict from Python and read it into an object in C#. Python code:
message = {'MessageType':"None", 'ContentType':"None", 'Content':"OK"}
message_blob = simplejson.dumps(message).encode(encoding = "UTF-8")
alive_socket.send(message_blob)
The message is sent as normal UTF-8 string or, if I use UTF-16, as "'\xff\xfe{\x00"\x00..." etc.
Code in C# is where my problem is:
string reply = client.Receive(Encoding.UTF8);
The UTF-8 message is received as "≻潃瑮湥≴›..." etc.
I tried to use UTF-16 and the message comes through OK, but the first symbols are still the little-endian \xFF \xFE BOM so when I try to feed it to the deserializer,
PythonMessage replyMessage = JsonConvert.DeserializeObject<PythonMessage>(reply);
//PythonMessage is just a very simple class with properties,
//not relevant to the problem
I get an error (obviously occurring at the first symbol, \xFF):
Unexpected character encountered while parsing value: .
Something is obviously wrong in the way I'm using encoding. Can you please show me the right way to do this?
The byte-order-mark is obligatory in UTF-16. You can use UTF-16LE or UTF-16BE to assume a particular byte order and the BOM will not be generated. That is, use:
message_blob = simplejson.dumps(message).encode(encoding = "UTF-16le")

How can I stop HTTP from escaping quotes?

I'm using C# to POST some data to a webserver running PHP.
I'm sending a JSON formatted object to the server in the POST data.
The data looks something like this when it leaves the C# program:
json_text={"abc":"hello", "dfg":"world"}
I have the server printing the data exactly as it received it using echo $_POST['json_text']; The script outputs the following:
{\"abc\":\"hello\", \"dfg\":\"world\"}
I'm not very familiar with how POST data is packaged into an HTTP packet. I opened up WireShark to look at how quotes are sent in POST data and it looks like they are replaced with %22. However, I tried replacing my quotes with %22 and it did NOT stop the quotes from being escaped when it is outputted.
Thank you
Turn off PHP's magic_quotes option. That's probably where the backslashes are coming from.
Setup your json_text object as follows, not quoting the property names and using single quotes instead:
json_text = { abc : 'hello', dfg : 'world' }

Line breaks ignored when sending mail as plain text

I have a text like " Hi, \r\n this is test \r\n Thanks" I am sending the mail using MailMessage class. I have set the "IsBodyHtml" property to false. The issue is that I am receiving mails without line breaks. Can you let me know what I am missing?
Use Environment.NewLinemsdn instead of \r\n.
We had the same problem, but if you define your message all at once in a String, as opposed to a StringBuilder, you can define your message like this:
string message = string.Format(
#"First Line: {0}
Second Line: {1}
ThirdLine: {2}", firstValue, secondValue, thirdValue);
Defining the message body like this, and setting IsBodyHtml = false, will give you the new lines that you want.
Otherwise, use StringBuilder
var sb = new StringBuilder();
sb.AppendLine("FirstLine");
sb.AppendLine("SecondLine");
This is a feature in Outlook, you can turn it off in Outlook. Go to Options - Mail - and under "Message Format" you uncheck "Remove extra line breaks in plain text messages".
Another solution is to add three spaces at the end of each line, when you send the mail. This seems to get Outlook to accept that it is not an extra line break.
If you are reading your mails from Outlook, it may be Outlook that is removing line breaks, thinking they are extra line breaks. Did you try reading your mails from another software - or maybe a webmail?
To be able to incorporate line breaks, rather than just plain test in your mail, you will need to have the body html set to true, I think.
A more tricky reason this may happen that I just had to deal with:
Your mail server manipulates outgoing messages and adds a html version to your otherwise text only message
I was having a similar problem where most of my line breaks were working but one was not. If I hit reply to the email that wasn't showing the line breaks, the original email text below the reply would show the line break (so this indicates it is an outlook issue). I tried the recommended answer of Environment.NewLine and that DID NOT change anything. In my case, adding a period at the end of the statement where I wanted the new line and then putting in a \r\n did the trick. Per a previous link I posted in this discussion, Outlook is using some rules to filter out line feeds and in the question that started this discussion I notice you do not have a period at the end of your sentence.
I was sending E-Mail notification via PowerShell script and also did not get any line breaks when viewing the mail in Outlook.
For me the solution in the .ps1 file was this:
$emailMessage.Body = "First Line" + "`r`n" + "Second Line"

Categories

Resources