Tuesday, November 27, 2007

GMail Recent Mode

Useful when using multiple clients to download your mails using POP3. To use it, your account name should be "recent:yourname@gmail.com" (without quotes, notice recent: in front of your gmail email). Also your Gmail Settings' Forwarding and POP/IMAP tab's POP Download should be Enable POP for all email and When messages are accessed with POP field should have Keep Gmai's copy in the Inbox selected.

Handling content compression with CFHTTP

Lots of web servers return compressed pages for faster delivery of pages. Our browsers happily decompress these pages on the fly and show them up. However, when using CFHTTP to get content from URLs if the server returns compressed content your in a bit of trouble.

The solution is easy: provide a HTTP header directive that specifies that your request does not accept compression and the web server should honor that by giving uncompressed content. To do this, your CFHTTP statement should look like:

resolveurl = Yes
throwonerror = Yes >
<cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0">
<cfhttpparam type="Header" name="TE" value="deflate;q=0">

Windows Mobile Messaging and GMail POP

Nice thing about google's POP/SMTP access is that it allows you to get rid of your unfriendly ISP's typically restrictive policy of sending out email via default SMTP port. Plus you get great anti-spam filters!

However, setting things up turned out to be a little less straight-forward. Initially, I gave up on Windows built-in messaging app once I could not set an outgoing server's port number (as required for gmail). I figured its yet another one of Microsoft's evil tricks. However, as it turns out (and not so surprisingly, I must add) I was wrong to judge too soon. In the mean time, I used google's nifty gmail Java app available from www.gmail.com/app. Works great except for deleting messages (this really ought to be simpler) as well as selecting more then one message AND the super-small scrollbar which is somewhat of a pain to work with. But apart from that (!) its really great! :)

In addition I got some feedback that it was virtually impossible to properly use gmail POP with multiple clients (Outlook 2003, Windows Mobile 6 Messaging). Apparently only one would download mails and the others would be left without those. I figured it was just a matter of properly configuring POP so when I gave it a shot. Tried downloading mail on my mobile and ... nothing happened. Hm. Go figure.

So, here is a quick and (almost) simple set of steps to configure proper gmail POP access from multiple devices with an accent on Windows Mobile 6 Messaging.

Setting up GMail POP Account Access on Windows Mobile 6 Messaging

  1. Start > Messaging (opens Select an Account screen)
  2. click New E-Mail Account (if you already have one configured then select your existing gmail account and then click Tools > Options... followed by another click on gmail account in the list of current accounts you have defined)
  3. enter your email address (eg xyz@gmail.com)
  4. Enter your name
  5. Enter gmail.com in the account display name
  6. for Incoming mail server type pop.gmail.com:995 (notice the :995 - that's the POP port number you need to specify as per gmail's official setup configuration)
  7. for Account Type choose POP3
  8. for User Name type (and this is the trick!) recent:xyz@gmail.com
  9. Type in your password (check Save password), click Next
  10. for outgoing SMTP mail server type smtp.gmail.com:587 (again, notice the port number 587 added after column) and check both checkboxes below the smtp server name for requiring authentication and to use same username for sending and receiving email
  11. click Advanced Server Settings and tick both checkboxes for Require SSL for Incoming E-mail as well as for Require SSL for Outgoing e-mail. Choose The Internet for the Network Connection dropdown on the same screen and click Done to continue with setup
  12. click Next
  13. Choose some frequency for automatic send and receive of emails (eg. Every 10 minutes) and select All Messages for Download Messages dropdown
  14. click Advanced Settings and under When Deleting Messages dropdown select Keep them on the server
  15. click Done and click Next to go to final step
  16. choose message format as HTML and message download limit of 2KB (both default values)
  17. click Finish
That's it! With the above setup my HTC Touch and Gmail work like a breeze.

Important trick is the use of "recent:" in your account name - this apparently relies on gmail's "recent mode" which allows multiple clients to access messages via POP without getting into that trouble with one client getting the messages and the others don't. Apart from that, make sure you use the port number for POP and SMTP server as outlined above. Thanx to this post for figuring that part.

This should be enough to get your Windows Mobile Messaging 6 application to happily start working with gmail for both sending and receiving email regardless of your ISP setting.

Hope it helps.

Saturday, November 24, 2007

Magento Getting Page Title

Magento is a great new open-source shopping cart engine written in PHP on top of Zend framework. It is highly configurable. Been trying to do some debugging and learning on the overall flow of things, so for those who are interested, read on...

I'm not yet sure how to get around talking back with the app so I've discovered the use of Mage::Registry(key) which is a central place that stores a lot of current variables during the execution of the request.

To get the title of the current page (as defined in the CMS backend page admin), you can do:
Mage::getSingleton('cms/page')->getTitle() == 'My Title')

Friday, November 23, 2007

Drupal Resources

Some links and pointers to materials that can be useful for folks interested in Drupal:

NVARCHAR MSSQL columns and cfqueryparam

According to CFMX 7 official documentation, using cfqueryparam's cfsqltype="cf_sql_varchar" is supposed to handle MSSQL server's varchar, nvarchar and sysname. Unfortunately, the nvarchar portion seems not to work so well, unless there's a setting I'm missing in the CF admin.

Typically, nvarchar is useful when saving unicode data. I'm dealing with diacritics and the only way to get diacritics to save properly was with the use of a following snippet:
update sometable set columnname=N'#somevariablename#'

The idea was to get rid of these poorly secured statements with the recommended SQL params instead. Unfortunately, when saving data using the cf_sql_varchar, I get ? instead of most of diacritics (things like čćpšžČĆŠĐŽ). Still looking into this thing so have reverted back to the above syntax.

Interestingly, for columns of type NTEXT using cf_sql_clob seems to work fine. Diacritics get saved properly as well. I've tried using cf_sql_longvarchar instead of cf_sql_varchar but there was no difference.

Stripping HTML Markup and Extra Whitespace from Strings

Needed a simple way of stripping HTML markup from a given string. Since this is a ColdFusion app, I ended up finding a useful blog entry at Ray Camden's blog: Quick example of cleaning up Verity results.

This is the gist of it:
<cfset var cleaned = rereplace(arguments.input, "<.*?>", "", "all")>
<cfset cleaned = rereplace(cleaned, "<.*?$", "", "all")>
<cfset cleaned = rereplace(cleaned, "^.*?>", "", "all")>
In addition, to get rid of extra white spaces, you can do this:

<cfset var cleaned = rereplace(arguments.input, "\s{2,}", " ", "all")>
The above regex would get rid of 2 or more white spaces from the text (since we got plenty of those once the markup was stripped from the original string.

Finally, to get the lovely formatting of code as seen above, check out http://formatmysourcecode.blogspot.com/. Learning on regular expressions? Go to http://www.regular-expressions.info/.

HTC Touch and Gmail

Got a brand-new HTC Touch 3450 PDA/Smartphone. Neat. Its not that hard to use and setup although there are some quirks especially with WIFI. Comes with Windows Mobile 6.

Been trying to use gmail as a hub to get/send email for the mobile device. Seems nice with their gmail java midlet available at http://gmail.com/app. Then I tried using calendar via http://www.google.com/calendar, notebook via http://www.google.com/notebook/m. Very nice although it would be cool to somehow integrate the on the Today screen of the phone. Hmmm....

So far, the only problem I can report is trying to use gtalk for some time with the electronic on-screen keyboard. I think its overall a little bit of a pain to write a lot. So, if you have to do that, consider getting a model with the slide-out keyboard. Otherwise its cool.