Monday, September 14, 2009

Syncing Thunderbird 2.0 mailbox with Blackberry for an Exchange account

My organization uses Microsoft Exchange as the Mail Server and a BES server to sync mails on my blackberry.

The mailbox on server is allowed only 50 MB of space and thus I need to continuously delete mails on the server. Previously I used POP to fetch mails from Exchange to Thunderbird mail client but this had sync issues (mails were downloaded multiple times, the read/unread information was different on mobile and desktop) once I configured my Blackberry using BES.

I recently shifted from POP to IMAP (had to get IMAP enabled from the administrator) and this has solved a number of problems.

I've created filters which automatically shift few mails to the local folders and I manually move emails to local folders whenever required. The move operation does not automatically compact (delete emails on mailbox which were moved/deleted locally) folders but the following will make that happen:

Goto Edit -> Preferences -> Advanced -> General -> Config Editor and then make the mail.imap.expunge_after_delete option as 'true'. Restart Thunderbird to use this config.

Secondly, I wanted the sent mails to be saved on the 'Sent Items' folder on the Exchange Server's mailbox. This can be achieved by subscribing to the 'Sent Items' folder and placing a copy of send messages in the 'Sent Items' folder. To achieve this:

1) Right click on the 'Inbox' for the IMAP account and click 'Subscribe'. Select the 'Sent Items' folder. You should now see the folder next to Inbox on the left panel.

2) Goto Edit -> Account Settings -> Copies & Folders and select 'Sent Items' as the Other folder under 'when sending messages, automatically' -> 'Place a copy in'.

Saturday, September 05, 2009

Setting up your mail using BIS (Blackberry Internet Service)

Once you've opted for blackberry services, the provider will setup an account on blackberry.com for you. For example, I'm using an Airtel connection and I access my account on http://www.airtel.blackberry.com/.

Once you log in, you'd probably want to add your official and personal e-mail. Setting up the email account is simple if you have a gmail account. Just enter your email address and password, it'll start delivering mails in minutes.

For your official id (for non Blackberry Enterprise Server users), blackberry will first try to automatically get the settings after you enter the e-mail/password and if it succeeds, you won't have to enter any more detail. But this could be troublesome for some, as in my case I wanted to setup using OWA (Outlook Web Access) and it picked the POP settings. A workaround is to enter the right e-mail id and a wrong password, this will throw up the settings page where you can manually select which protocol you want to use.

Lastly, I've noticed that mails sent to my gmail address are delivered instantly (using Push I guess) but mails sent to a POP or OWA account takes a few minutes to reach my phone. I guess if you are using Google for your official mails (http://www.google.com/apps/intl/en/business/index.html) then the delivery would be instant.

Wednesday, August 26, 2009

PHP Error after updating to 5.2.6 (Ubuntu 9.04)

After updating to PHP 5.2.6 using the update manager, I got the following error:

php: symbol lookup error: /usr/lib/php5/20060613+lfs/pdo_mysql.so: undefined symbol: php_pdo_declare_long_constant

To fix, I simply installed the php5-mysql package using Synaptic Package Manager.

Reference: https://lists.ubuntu.com/archives/ubuntu-server-bugs/2009-February/009968.html

Sunday, July 19, 2009

Migrating from Outlook 2007 to Thunderbird on Linux

I recently migrated to Thunderbird on Linux from Microsoft Outlook 2007 (on Windows XP).

Following are the steps (should work for Outlook Express and older Outlook versions as well):

1) Install Thunderbird on Windows (Yes! On Windows first).
2) After installation go to 'Tools->Import'. Select Mails and then Outlook. This process might take some time and you should ensure that there is sufficient disk space available. Refer to http://kb.mozillazine.org/Moving_your_mail_storage_location_(Thunderbird) , if you want to change the location of Local Folders on Thunderbird.
3) Note the location where Thunderbird keeps it's folders (Tools->Account Settings->Local Folders will show the location). Copy Local Folders to a USB/External Drive (if the current location is not accessible from Linux).
4) On Linux, Install Thunderbird. Start Thunderbird. Configure your E-mail Account. Note the location where your local folders are located.
5) Create a 'New Folder' under 'Local Folders'(say 'Import'). Create another sub-folder inside 'Import'.
6) Go to the location where you can find the local folders. You should be able to locate the Import.sbd folder inside it.
7) From the original location where you imported the Outlook mails using Windows Thunderbird, copy contents of the Outlook.sbd folder to the Import.sbd on linux.
8) Ensure that the owner and permissions of all content under Import.sbd is appropriate (refer to the Inbox/Import folder/file permissions).
9) Start Thunderburd.

You should be able to see all your Outlook 2007 mails under the Import Folder. Initially they will all appear as un-read.

Thursday, June 18, 2009

Memory leak in xcache extension of PHP

I recently encountered memory leak while using the xcache extension (version 1.2) with PHP 5.2.6.

The following code confirms the memory leak:

$data = "data";
xcache_set("key",$data);
while(1) {
$a = xcache_get("key");
echo "Memory Usage :".memory_get_usage()."\n";
}

This seems like a known issue and a worksround is suggested by oli at http://xcache.lighttpd.net/ticket/95 . Simply type-cast the data to a string while using xcache_set. The following works without any memory leak:

$data = "data";
xcache_set("key",(string)$data);
while(1) {
$a = xcache_get("key");
echo "Memory Usage :".memory_get_usage()."\n";
}

Don't know the root cause of this issue but the workaround helped.

Tuesday, June 09, 2009

Browsers are getting faster!!

Google Chrome has raised the bar for browser speeds as far as rendering/javascript is concerned. Ever since it's launch, all other browsers are releasing newer and faster versions one by one.

I recently tried the following browsers:

1) Opera 9.64
2) Chrome 1.0
3) IE 8
4) Firefox 3.5
5) Safari 4

Apart from IE 8 (whose javascript processing is awful) all the browsers are amazingly fast compared to their predecessors. I use to think that browsing was slow mainly because of the internet speed but it seems that the browser rendering speed has a major role to play.

Firefox 3.5 version is beta as of now but the final release should be out soon. I kind of like Firefox because of the add-ons available with it. There's just about any kind of extension that you'd like.

If given an option where all these browsers perform almost at par in terms of speed (5% here or there does not really matter) i'd use Firefox.

Wednesday, June 03, 2009

Tagging pattern in an element of XML using PHP

Recently I had a requirement to tag a pattern within an element of the provided XML.

Following code worked:
<?php

function replaceElementWithTaggedElement($doc, $element, $pattern, $tagNameForPattern)
{
$newElement = $doc->appendChild(new domelement($element->nodeName));

$content = $element->nodeValue;
while(preg_match($pattern, $content, $matches, PREG_OFFSET_CAPTURE))
{
$match = $matches[0][0];
$offset = $matches[0][1];
$firstPart = substr($content,0,$offset);
$secondPart = substr($content,$offset+strlen($match));
$newElement->appendChild($doc->createTextNode($firstPart));

$taggedElement = $doc->createElement($tagNameForPattern);
$taggedElement->appendChild($doc->createTextNode($match));
$newElement->appendChild($taggedElement);

$content = $secondPart;
}
$newElement->appendChild($doc->createTextNode($content));

$element->parentNode->replaceChild($newElement, $element);
}

$doc = new DOMDocument();
$doc->loadXML("<root><one>This is the first text node</one><two>This is the second text node and the word to be highlighted is second</two></root>");
$oldElement = $doc->getElementsByTagName("two")->item(0);

replaceElementWithTaggedElement($doc, $oldElement, "/second/", "tagged");

echo $doc->saveXML();
?>

OUTPUT

<?xml version="1.0"?>
<root><one>This is the first text node</one><two>This is the <tagged>second</tagged> text node and the word to be highlighted is <tagged>second</tagged></two></root>

Saturday, April 18, 2009

Gearman Client and Worker with PHP

To write the Gearman client or worker in PHP there are 2 options available:

1) Net_Gearman pear package: http://pear.php.net/package/Net_Gearman/download/0.1.1
2) Gearman PHP Extension: http://www.gearman.org/doku.php?id=download

As per my experiments, Net_Gearman does not processes all requests when multiple (more than 5) simultaneous clients are sending requests.

The PHP extension available on gearman.org is better and initial tests are encouraging.

I encourage using the Gearman server and library available on gearman.org as well.

Friday, March 27, 2009

Keyword Suggestor in PHP 5

To add a feature like Google's Did You Mean in your PHP application a reasonable solution is to use PHP's pspell library.

This comes bundled with PHP (http://php.net/pspell). Compile PHP with the '--with-pspell' option but before this ensure that you have aspell (version 0.6 or above) already installed.

Custom dictionary can also be created for aspell but this will require the aspell-lang package. You can download the same from here.

Details on how to create your custom dictionary are available here under the 'Creating a Custom Language Dictionary' section.

Saturday, February 21, 2009

Using multiple field separators with gawk

To define multiple field separators with gawk, set the FS variable with the appropriate regex.

For example, to use comma(,), colon(:) and equal-to (=) as field separators, following can be used

cat file.txt | gawk '{FS = "[:,=]+"} {print $3" "$5}'

The above example also prints the 3rd and 5th field elements.

Tuesday, February 10, 2009

Altering a HUGE MyISAM table in MySQL

I recently tried to alter a MyISAM table with appx. 300 million records (15 GB MYD size) having unique indexes and it took forever to execute (more than 20 days).

Then, I came across this . The following suggestion simply rocks:

- You can create table of the same structure without keys,
- load data into it to get correct .MYD,
- Create table with all keys defined and copy over .frm and .MYI files from it,
- followed by FLUSH TABLES.
- Now you can use REPAIR TABLE to rebuild all keys by sort, including UNIQUE keys.

The alter completed within 5 hours flat. Just incredible!!

Sunday, February 01, 2009

Google Calendar - Mobile Setup

I recently tried the Mobile Setup provided by Google Calendar and thought of sharing it.

After you login to Google Calendar (http://calendar.google.com/) click on the Settings->Mobile Setup Tab. Enter your mobile number and validate your number.

Once done, you can now ask Google Calendar to send Event Reminders through SMS (For free):







This is a fantastic feature and will remind you of calendar events even if you are away from your Desktop and do not have a PDA/Smartphone to sync your calendar.

For MS Outlook users, Google also provides a Calendar Sync feature (http://www.google.com/support/calendar/bin/answer.py?answer=98563) which will keep your Google and Outlook calendar in sync.

Thus, you can now get SMS before any personal or official event :)

Which Blackberry is the best?

There are a bunch off new Blackberries in the market these days. I'll take a look at each and give my views:

* Blackberry Bold (Powerful)
This is a power-packed Blackberry. It supports almost all the wireless protocols out there including WiFi and 3G. The screen resolution is equivalent to an iPhone even though the screen size is smaller and thus gives a very clear view. The processor and memory of this phone is better than any other blackberry (it will respond faster to your commands compared to other blackberries). The only negative aspect I can think of is the size. It's bigger than the 8900 or the pearl and will need a bigger pocket to go into.

* Blackberry Storm (Touch Screen)
After viewing the commercials, I was really exited about this phone. It was suppose to give serious competition to the iPhone as it is a blackberry with the touch screen. But sadly after going through few videos in YouTube it seems that the Storm lacks in power and has a slow response time. Moving through pictures/videos can be a pain. I would not like a smartphone which is slow.

* Blackberry Pearl Flip
When the original pearl was launched it was clearly a winner. The blackberry which is not FAT and fits in your hand comfortably. With the Flip, RIM has taken Pearl to the next level. So, if you want a sleek/small blackberry, then this is THE one for you. But you will have to compromise on the performance and screen quality if you settle for this one.

* Blackberry 8900 (Javelin)
This one comes really close to the Bold and will probably win if you consider the size. It's smaller than the Bold and has those curves which you will love. It has Wifi but no 3G. If you can compromise a bit on power and are not particular about having a 3G smartphone, then this is the one for you.

Tuesday, January 06, 2009

Sample C Server which handles zombie processes

After a bit of googling I managed to create a simple Server (written in C) which accepts connection on port 5000 and spawns a new thread to handle each request:



#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <signal.h>

#define MAX_CLIENT 10

void zombie_handler(int iSignal)
{
signal(SIGCHLD,zombie_handler); //reset handler to catch SIGCHLD for next time;
int status;
pid_t pid;

pid = wait(&status); //After wait, child is definitely freed.
printf("pid = %d , status = %d\n", pid, status);
}

int main(int argc, char *argv[])
{
int tcp_sockfd, k, portno=0, tcp_newsockfd, n;
struct sockaddr_in myServer, myClient;
char bufferin[256],bufferout[256],ipaddress[20],hostname[50];
char s[INET6_ADDRSTRLEN];
struct hostent *host;
pid_t pid=-1;

signal(SIGCHLD,zombie_handler);

//////////////////// Create a TCP Socket and get the port number dynamically

tcp_sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (tcp_sockfd < 0)
error("ERROR opening TCP socket");

bzero((char *) &myServer, sizeof(myServer));
myServer.sin_family = AF_INET;
myServer.sin_addr.s_addr = htonl(INADDR_ANY);
myServer.sin_port = htons(5000);
if (bind(tcp_sockfd, (struct sockaddr *) &myServer, sizeof(myServer)) < 0)
error("ERROR on binding");

portno = ntohs(myServer.sin_port);

if(gethostname(hostname,50) == -1) // get hostname of the chat server machine
error("ERROR on gethostname");
host = gethostbyname(hostname); // get host information
strcpy(ipaddress,(char *)inet_ntoa(*(long*)host->h_addr_list[0])); //get IP Address string format

printf("Chat Server IP Address : %s\n",ipaddress);
printf("Chat Server Port Number : %d\n",portno);

//////////////////////////////////////// Now wait for connection from Client
if(listen(tcp_sockfd,MAX_CLIENT) == -1)
error("ERROR on listen");

while(1)
{
printf("Waiting for connection...\n");
k=sizeof(myClient);
tcp_newsockfd = accept(tcp_sockfd,(struct sockaddr *)&myClient,&k);
if (tcp_newsockfd == -1) {
printf("error in accept\n");
continue;
}

if (!fork()) { // this is the child process
close(tcp_sockfd); // child doesn't need the listener
if (send(tcp_newsockfd, "Hello, world!", 13, 0) == -1)
perror("send");
close(tcp_newsockfd);
exit(0);
}
close(tcp_newsockfd); // parent doesn't need this


}
close(tcp_sockfd);

return 0;
}



Here I simply write a string (Hello World!) to the client. You may perform multiple reads/writes.

The zombie_handler function ensures that no zombie processes are created once the child exists.