Wednesday, August 15, 2012

E-Mail - Going old school


Over the past couple of days I’ve been thinking about how it would all look to open your mail using just the command prompt. I know it sounds crazy, esp. when you have all these wonderful browsers and mail clients out there. But well, thinking over stuffs like these keeps me going. So, brooding over this for a couple of days gave me a solution.

Below I’ve mentioned in detail the steps I’ve followed to open my Gmail account via Command Prompt.

First off, you will need a tool called Stunnel (found here). This program works as an SSL encryption wrapper between remote clients and local or remote servers. (Most E-Mail services like Gmail uses SSL encryption for the traffic between the server and the client)

Presuming that you have downloaded and installed Stunnel, it is time we get to business.
  1. Once Stunnel is installed, locate the stunnel.conf file in the installation directory and make the below changes to stunnel.conf file.
    • Define the protocols and services you would be using 
      • sslVersion = all 
      • options = NO_SSLv2  
      • client = yes  
      • options = DONT_INSERT_EMPTY_FRAGMENTS 
    • Configure the Gmail POP server 
      • [pop3s]  
      • accept = 2302  
      • connect = pop.gmail.com:995  
      I’ve attached here a version of the stunnel.conf file, that you can use out of the box. 
      The above entries configures your system to connect to pop.gmail.com:995 (through SSL) and to accept traffic at port 2302 of your machine to be directed to the Gmail POP server
  2. Make sure you have Telnet services up and running in your machine  
    • For Windows 7, type in ‘optionalfeatures’ at Run (Win + ‘R’ - Optionalfeatures) and enable both Telnet client and server  
    • Enabling Telnet services for other version of Windows can be easily looked up from Google  
  3. Once done, fire up Stunnel and reload the stunnel.conf file (Configuration - Reload Stunnel.conf)  
  4. Now Stunnel has configured your system to initiate an SSL connection at port 2302 (configured in stunnel.conf)  
  5. Open Command Prompt (Win + ‘R’ - CMD) and type in the following 
Telnet Localhost 2302
This brings up the following: +OK Gpop ready for requests from 111.222.333.444 abcdefghijklmn.20 (Where 111.222.333.444 is your IP)
Key in USER followed by your user name, which is responded by +OK send PASS
Now type your password after the PASS command.
If the server accepts your username and password it responds with the following message +OK Welcome.

Now you are up and running!

Here is a sample of the whole steps, the way it would appear on the screen for an user with the below credentials
        Username: test.user
        Password: test.password

Telnet Localhost 2303 
+OK Gpop ready for requests from 111.222.333.444 abcdefghijklmn.20 
USER test.user 
+OK send PASS 
PASS test.password 
+OK Welcome. 
STAT 
+OK 123 123456 
QUIT 
+OK Farewell. 

You can use the below commands to browse through your mails
  • STAT - Retrieves the no# of messages in your mailbox 
  • RETR X - Displays the Xth message in your inbox 
  • TOP 1 10 - Retrieves the first 10 lines of message 1 
  • DELE X - Marks message X for deletion 
  • QUIT - Closes the session 

The RFC 1939 describes in detail the various POP commands and its usage. So if you need a better grasp of the commands given above, I suggest you check out this link.

Please do note the following
  1. Any invalid command/character closes the session 
  2. Passwords are entered as plain text on the command console and hence this is not a safe way of accessing your mail box. Any person looking at your screen can read the password off your screen. (I am not responsible for any password loss/theft on account of this) 

NB: The details above give you a hang of what happens when you access your emails via your browser/client. This is only for educational purposes and is not to be misused. I will not be responsible for any irresponsible/careless use of the above steps.

Well, that’s it for now! Try it out and let me know if you face any difficulties.

Monday, November 23, 2009

Monitor Power Saver


Nearly all of us employ some power saving scheme while working with our PCs' like, switching off the monitors (physically); setting the screensavers to kick in after a preset duration, putting the system to stand-by or totally powering down the system.

Consider this scenario - you want to take a 5 minute break and your screensaver is set to kick in around 3 minutes. You don't want to put the system to stand-by or totally power down the system as the lag required to get the system up and working is bit annoying. (You may have set up an antivirus scan, update or download which you don't want to be bothered with while you power down). So, your best bet is to power down the monitor for the 5 min and switch it on when you are back or let the screensaver kick in (which would give you only (5-3) 2 minute of power saving).

Switching on and off (physically) the power switch of your monitor isn't a great idea, because on a long run it can damage the switch (Monitor switches aren't meant to take heavy duty switch on and off cycles. Present day monitors are so designed to be left on for hours, while the power saving strategy has to be implemented by the installed softwares).

Well, this was one question that has been bothering me quiet recently. Thankfully a quick google search took me to the right direction. Below I've provided a small program (in C++), that could help solve a situation like the one described above.

// PROGRAM TO TURN OFF MONITOR IN C++

#include
using namespace std;

int main()
{
SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2);
return 0;
}

//EOF

The source code and executable can be downloaded here (6.40 KB).
(Open the link in new tab/window and save file as PowerSaver.rar)

A little light on the SendMessage function.

LRESULT SendMessage(
HWND hWnd, // handle of destination window
UINT Msg, // message to send
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);

The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message.

Parameters:
hWnd - Handle to the window whose window procedure will receive the message. If you don't want to bother creating a window to send the message to, you can send the message to all top level windows (HWND_BROADCAST) or you can use GetDesktopWindow function sending the message to the desktop window.
Msg - Specifies the message to be sent (WM_SYSCOMMAND).
wParam - Specifies additional message-specific information (SC_MONITORPOWER).
lParam - Specifies additional message-specific information.
1 - the display is going to low power.
2 - the display is being shut off.
-1 - the display is being turned on (undocumented value).

This program should compile with almost any C compilers without any errors, to give you an efficient monitor friendly power management application.

When the program is executed it forces the display to go into 'power off' state and (program) is terminated. Upon mouse movement or keyboard activity, the display is restored.

Try linking the program with any key on your keyboard (multimedia keyboard) or put a shortcut to the program on your desktop or assign a keyboard shortcut for the program.

Thanks to all people out there who helped me with this program.