{{error}}
{{(quickSearchResults.length>10)?'10+':(quickSearchResults.length)}} {{(quickSearchResults.length==1)?'result':'results'}}
{{result.title}} {{result.timeStamp | mysql2ymd }}
I am sorry, no such article was written yet.
How to write a simple Light SMTP Server in C#
Sample of a small C# SMTP server with the following features:
  • 17KB source code;
  • five files of code only;
  • able to receive mails;
  • relay (forward) mails to external servers;
  • able to resolve the MX machine IPs for external mails;
  • mails to external recipients (external elaying) requires authentication.
The components of the code are:
  1. "Listener" daemon that takes the incoming SMTP requests;
  2. "MXDiscovery" module able to identify the IP of the external recipient servers;
  3. "Sender" component that is responsible for forwarding the message to external recipients;
  4. "SMTP" library with useful functions;
  5. "SMTPServer" the main application that starts the listener.

I hope this information might be useful for others, too.
5 files attached: SMTPServer.cs Listener.cs MXDiscovery.cs Sender.cs SMTP.cs
SMTPServer.cs Listener.cs MXDiscovery.cs Sender.cs SMTP.cs
Email obfuscator
When I decided to publish my CV on a web page (http://dragos-matei.sorescu.eu) I wanted to publish also my email, but without letting the bots read it.
So, I came with the following solution:
  1. encode the email in some kind;
  2. let the browser decode it after the page gets loaded.
For this I used the following encoded text:
	
		<%icon:email%>[b36]831898108[b36][b36]1348423876[b36]@[b36]27913917[b36].[b36]16438[b36]
	
The JavaScript to decode it is attached.
A small demonstration of the algorithm is put also below:
SourceEncodingDecoding
 
 
1 files attached: Decode.js
Decode.js
Search functionality enabled on www.sorescu.eu
Now the site http://www.sorescu.eu/ offers a search functionality in the left bar.
The code is relatively simple, with two components, client-side and server-side.
Notes:
  • the PSP is a wrapper syntax on top of PHP;
  • after loading data, the client is responsible with formatting with JQuery the result;
  • in case of fast typing it is possible that multiple distinct requests to come in a different order (I shall fix it by adding a counter logic in few minutes).
2 files attached: ClientSide.html ServerSide.php
ClientSide.html ServerSide.php
Small Java Image Resizing Utility
Another small challenge; one guy came to me with 550 photographs in around 110 folders (they represent a tree structure of content images to be delivered and browsed by a front-end web application).

The challenge was to compress and resize all the images to improve the browsing performance.

Below is the code I wrote to perform this task.
My inspiration was http://www.mkyong.com/java/how-to-resize-an-image-in-java/ with the following small and compact code:
BufferedImage resizedImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, type);
Graphics2D g = resizedImage.createGraphics();
g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null);
g.dispose();
.
1 files attached: ImageResize.java
ImageResize.java
Screen Capture Update
My wife, the user of the Screen Capture application as described in  http://www.sorescu.eu/article/120220221500/Free-Screen-Capture-application explained me that she needs to run it also while in Full Screen mode.


For this I had to hook to the Windows Hot Key events, after I registered with the desired shortcut.

The chosen shortcut is <CTRL>+<ALT>+<PRINT_SCREEN>, and the code update is as in file below. Main call as following:
Thread t=new Thread(new ThreadStart(ProcessHotKey));
            t.IsBackground=true;
            t.Start();
Worthy mentioning are the following:
  • I used
    GetMessage(ref msg,IntPtr.Zero,0,0)
    for avoiding message queues to any form, but to the current thread;
  • It was required
    int hashCode=("hash-"+modifiers+"-"+key).GetHashCode();
    to ensure that the Hot Key is unique in Windows;
  • The Hot Key handler had to be ran in a separate thread, using
    new Thread(new ThreadStart(ProcessHotKey))
1 files attached: RegisterHotKey.cs
RegisterHotKey.cs
A small Java program to generate transparent images (for dynamic background colours)
Somebody requested me to generate a web page with a wall background that should change the wall colour based on the user's desire.
I thought a transparency-enabled background will suffice, with a dynamic background of the image.
Steps:
  1. Take the background image from my customer;
  2. Generate a mask image as a copy of the background image, and remove the area (set it to black) where I want to have transparency;
  3. Run the Java program that is written below;
  4. Use the final result image and put it in a web page.
You can check the result (while the web page is still there) at: http://dev-alexandru-doors.sorescu.eu/products-en_GB where you may click any image from gallery and the background image will appear.
1 files attached: ImageTansparency.java
ImageTansparency.java
Sending dynamic client-side parameters in URL fragments and manipulating them
Seldom I was in need to perform client filtering on tables and other data, and eventually save the filter. One solution was sending the filter to the server and generate the filtered page.
The functions below (I am using them few years already in Internet Explorer) are used to store and get the properties from fragments.
Some useful clues:
  • When the page is loaded, check all the fragment parameters and update the controls and perform filtering, etc.;
  • Whenever you update a filter in a text field, etc., you can save it in the fragment;
  • You can send the link with fragment to anybody else, and if the first bullet (filter executed on page loading) is accomplished, the URL receiver will see the same page as you.
1 files attached: getFragmentValues.js
getFragmentValues.js
Scripted C# - or how to run dynamic C# code, without compilation
As I started to develop small applications in C#, I thought why shouldn't I use the same paradigms that I used in Java... dynamic code execution, execution without compile/build/deploy process, hot-swap, etc.

I am far away from acomplishing the same functionality, but I started with writing a small program (81 lines) mentioned below.

When executing, it is able to compile and execute C# code that is written in text files, on the spot.

The mechanism is quite simple: it expects in the command line the name of an XML file (mentioned below this script) that describes:
  • the list of CS files that should be compiled;
  • the list of external binaries, if required;
  • the title of the application;
  • the entry point (the class name that contains the Main function).
An example (SMTPServer.csscriptof the input XML looks like attached.
Useful information:
  • the class mentioned in the CSScript/EntryClass node must have a Main(string[]args) method;
  • the Main method must be public and static!
  • additional parameters to be sent to the Main method are added to the executed command line!
Example of using the script attached.
In my development (that I started yesterday evening) I used some information from the following links:
The application code is straight forward, and I don't think any comment is required. If you need any comment, then either you should learn programming, or study a bit some C-like languages.

If you wonder why I don't also give the EXE file, please feel free to open the Visual Studio, create an empty project, add a class and paste this code.
3 files attached: RunCS.cs SMTPServer.csscript start.cmd
RunCS.cs SMTPServer.csscript start.cmd
Translating the DOCX file in machine-readable contents
One of my last tasks is to build clear requirements based on customer WinWord documents; I also do have a strong feeling that the documentation will change in time, and it will be a dirty work to trace it.
As a consequence, I wrote a small utility to render to the browser the contents (not rendition) of a diven DOCX file. And the transformation (in incipient phase) is below.
2 files attached: RenderWindWord.dsp Transform.xsl
RenderWindWord.dsp Transform.xsl
Outgoing mails got blocked by Trend Microsystems firewall
My mail server (developed in .NET) is running on IP 188.240.44.77. I used to send and receive mails, everything is fine. However, there is a domain (let's say anonymousdomain.com) where everytime I try to send an email I get the error below:
550 5.7.1 Mail from 188.240.44.77 blocked using Trend Micro RBL+. Please see http://www.mail-abuse.com/cgi-bin/lookup?ip_address=188.240.44.77
Fine, I understand, and I do remember I tried to test my outgoing SMTP connections with another email address hosted on anonymousdomain.com. At the same time I noticed that the Google servers were delivering just fine my mails, without any issues.
I do acknowledge my actions were not ethical, moral, maybe not even legal to do in some countries (running mail tests on other people's addresses).
As a step forward, I shall contact the Trend Microsystems http://www.mail-abuse.com team to inform them that those mails were legitimate and for testing purposes, hoping I shall be removed from the black list.