Pixelastic

You can clip our wings but we will always remember what it was like to fly.

Posts tagged with "squirrelMail"

cakePHP wrapper for EmailComponent::send()

As I already wrote in a previous post, the cakePHP EmailComponent seems to have some quirks, forcing me to add more code to send an email.

I stumbled upon one more issue today : a View poisoning coming from the EmailComponent. Some vars I was passing to my view through the use of a custom Helper were wipe away if I send a mail in the same request.

It took me some time to track it down, but I finally decided that I'll now wrap calls to $this->Email->send() into a __sendEmail() custom method where I'll add my tweaks.

This will help migrating to a newer cake version easier when those bugs will be fixed.

Easy debug

Debugging emails is not an easy task, but is greatly eased by cake. One can set the delivery type to debug and the mail will be generated like a normal mail, but won't be sent. Instead, its content will be saved in Session.

My wrapper will allow switching from normal to debug mail thanks to an argument.

View cleaning

I'll also clear the ClassRegistry from the View created by the EmailComponent. The Email view is shared with the display view and this can result in vars being lost or not correctly set. I think all those troubles are gone in cake 2.0 but I haven't tested it yet.

The __sendMail method

Here is the method code. You should add it to your AppController :

function __sendMail($sendAsDebug = false) {
if (empty($this->Email)) {
return false;
}
// Debug mode
if (!empty($sendAsDebug)) {
$this->Email->delivery = 'debug';
}
// We force adding the boundaries and header otherwise some webmail (like SquirelMail) won't correctly display them
$this->Email->_createboundary();
$this->Email->__header[] = 'MIME-Version: 1.0';

$this->Email->send();

// We display debug info
if (!empty($sendAsDebug)) {
debug($this->Session->read('Message.email.message'), true);
}
// We also need to clear the generated view so our display does not get poisoned by the Email display
ClassRegistry::removeObject('view');
}

 

Migrating mails from GMail to other IMAP server

I have previously blogged on how I migrate mails from one IMAP server to another. Today I had to migrate some mails again.

My client's staff wasn't happy about the GMail webmail we gave them. The lack of a true "Draft" feature (one tha could be used and reused) had them drop a lot of productivity, so we decided to get back to Squirel Mail.

I started by manually recreating all the email adresses on the back-end on the Dreamhost server. Once at least one address is created, Dreamhost automatically creates the matching A and MX records.

I had to update my zone file on my registrar to update the previously MX and A records that were set to point to Google and updated to point to Dreamhost. I have to use an intermediate zone file on my registrar because I'm dealing with a limitation of the .fr TLD here.

Once the zone were updated and changes repercuted accross the network, I connected to the new Squirel mail. My inbox was empty.

So I ran imapsync to copy all mails from the google hosted service to my new server.

The syntax to be used is a little different than the one I mentioned on my previous post, so here it is :

imapsync --host1 imap.gmail.com --ssl1 --authmech1 LOGIN --user1 foo@domain.fr --passfile1 /path/to/pass1 --host2 208.97.*.* --user2 foo@domain.fr --passfile2 /path/to/pass2 --useheader="X-GMail-Received" --useheader 'Message-Id' --noauthmd5

After that, I reloaded my Squirel Mail inbox, and it was populated. I just had to do that for every account.

Displaying HTML mails sent from cakePHP in SquirrelMail

I just stumble upon the fact that my automated multipart (text + html) mails sent from my apps weren't correctly displayed on SquirrelMail.

I'm personnaly using GMail for my day to day email needs, but one of my client was using the default SquirrelMail (v1.4.21) install on their Dreamhost account. The received mails are not correctly parsed and get displayed as plain text, even if the header clearly specifiy a Content-Type: multipart/alternative; boundary="alt-"

The first culprit was that no boundary were given. This does not seem to cause GMail any problem, but I thought that SquirrelMail may choke on that. So I manually added a $this->Email->_createboundary(); call before my $this->Email->send();

Still, no succes. After some googling I found a bug report for a similar problem. I tried adding the suggested MIME header, and that solved my problem.

So here's my updated code :

$this->Email->sendAs = 'both';
$this->Email->_createboundary();
$this->Email->__header[] = 'MIME-Version: 1.0';
$this->Email->send();

I'll now have to add those two additional line of code everytime I'll have to send a multipart (html + text) email in cakePHP, until it get fixed (no specified milestone).

Migrating mails from IMAP to IMAP (part 1/2)

One of my clients wanted to change its hosting provider because of almost constant downtime. I suggested that we move the whole site and the associated email addresses to Dreamhost.

He is heavily using its webmail, with a dozen of different accounts, all with custom address book and drafts to reuse.

I had already moved a previous site of the same client to a GMail powered webmail and he wasn't so satisfied of it because of the lack of a "draft" feature that would allow him to reuse the same message templates.

Its current webmail is powered by Imp (Horde) and the default Dreamhost webmail is Squirel Mail.

So now I'm faced with a challenge. Which webmail should I choose and how will I initiate the migration ?

Contestant 1 : Horde

The easiest way would have been to reuse Horde. Horde has a nifty export/import function. It means that I could have exported the settings on the current host and imported them back in the new host.

Unfortunatly, Horde is not pre-installed on Dreamhost. It means I would have to install it and I don't really want to do it. This is not my area of expertise and if something goes wrong it will take me ages to fix.

Additionnaly, the default php5 install on Dreamhost lacks the IMAP extension needed and SSL connection requires an additional monthly fee.

That would be the better solution for the client, but I don't feel capable of doing it.

Contestant 2 : Squirel Mail

Squirel Mail is the default webmail on Dreamhost. It means that they do handle all the heavy stuff of configuring it and making sure it does not crash.

They assure me that I can have unlimited hosting of my mails, the only limits are a maximum of 100 SMTP sending per hour and no attached filed > 7Mo.

Those are almost no issues at all, we can handle that. I just have to check if the 100 sending per hour is for each mail address or for the entire account.

The only problem will be that I can't export/import the horde feature into Squirel.

What I could do however is synchronize the two IMAP servers, effectively copying all the mail from the current one to the new. Unfortunatly, there is no easy way to do that.

The Dreamhost support even told me that it was impossible. I found a linux command named imapsynch however that maybe could help, but I'll need to know the name of the dreamhost imap server and needed credentials to connect to it. I'll sort this out with them.

Contestant 3 : GMail

I've already set mails up with GMail a couple of times in the past so this won't be too hard. Could take some times, but nothing difficult about that.

I may be able to copy the current mails to the GMail server, I've seen some articles on the subject floating on the network, but I'll definitly won't be able to copy drafts.

Conclusion

I'm still in contact with the Dreamhost support to choose the better option. I don't think I'll install Horde, this will be too much work. I guess I'll go with the second option of migrating mails to Squirel Mail.

Whatever solution I'll pick, I'll be sure to post the whole details here for others to follow.

Update

I finally won't have to migrate mails, the client makes regular POP backup of its mails so he will just do one more right before the transfer and will start over with a brand new mail boxes. Concerning the drafts, he will manually copy-paste them from one webmail to the other and he told me that he wasn't using the address book...

So it appears that I'll just have to change the DNS to point to the new webmail and create a temporary CNAME to still access the old webmail on the old server until the migration is totally over.

Re-update

In fact, it appears that I won't be able to access both webmail at the same time. I'll have DNS issues, and the registrar panel that I have is very basic, I won't be able to fine tuned it correctly.

It seems that I'll have to migrate mails from one server to the other.

Why is my disk full ?

Ok, so remember when I was writing about that client of mine who had trouble with its SquirelMail implementation. I thought it was a problem of SquirelMail having trouble dealing with large directories.

It was not exactly that, it more was a question of the IMAP server having issues with disk space. I made some backups of the mails, cleaned it up a little then everything went fine.

But suddenly today, the same SquirrelMail started acting funny, blocking some login attempt telling me that the IMAP server stopped responding, or displaying message list without subject nor owner.

Tired all of this, I decided (my client) to move its whole mail system to GMail, using the Google system, while keeping my clients domain name. To finish the registration process at Gmail, I had to put a googlehostedservice.html file online on the domain to prove that I am the owner and...

452 Transfer aborted.  No space left on device

Here is what the FTP server answered. What ? No more space ? But, but, but, but I just cleaned it all, deleting a whole 1Go log file. Wtf ?

I connect to the server and got the list of the biggest files and directories by doing a :

find  /var -type f -ls | sort -k 7 -r -n | head -10

I found that the maillog was 1.1Go... I deleted it and hurry the Gmail activation process. Problem solved.

Debugging a Squirrel webmail

This is a quick blogpost, essentially as a reminder for myself :

A client of mine is using the Squirrel mail webmail. Once in a while, I have a call from him telling me that he can't access its account. The cause is always the same : there is way too much mails saved in his account and Squirrel mail choke on this, refusing to display the page.

The solution is simple, I just have to remove all the mails (except maybe the 100 or so last ones) and save them in a another directory, for archiving. The directory to save is /home/mailusers/c/contact/cur

But, thinking I was clever, instead of copying all the files to a new cur-save-2009 directory I thought it would be faster to rename the current directory to cur-save-2009 and create a new empty cur dir. Except that I forgot that I was loggued in as root and the directory must have a user/group set as postfix...

That's it, I just had to not forgot to set the owner/group of the cur/ directory as postfix once cleared.