All the stuff I’m likely to forget otherwise!

Running Ubuntu 6.10 under MS Virtual PC 2007

I used to have a dual-boot PC with Windows and Fedora Core Linux but since I got a nice shiny new Dell with a Raid 1 array mirroring across two hard disks I’ve been a bit scared to do that. Plus I rely on it too much to earn my keep to mess around with it.

Because of this I decided to try out Microsoft Virtual PC and to start off with the 2007 beta version. For some reason, maybe after reading the review on distrowatch.com, I decided to download Ubuntu 6.10.

I soon ran into problems with messed up graphics partway through the install. Googling, as usual, turned up some suggestions but none of these seemed to work. In the end the solution was to:

  1. Create the new virtual machine and load the CD or ISO image as preferred
  2. On the Ubuntu startup screen, before you select an option from the menu hit F4 and select ‘800×600x16′
  3. Select ‘Start Ubuntu in Safe Graphics Mode
  4. Wait for a few minutes and eventually you’ll get a screen of messed up graphics
  5. Press Ctrl-Alt-F1 - this will take you out of X-Windows and give you a command prompt
  6. At the Command prompt enter:
    • sudo nano /etc/X11/xorg.conf
    • In the ‘Section “Screen” ‘ part of xorg.config change the value of ‘DefaultDepth’ from 24 to 16
    • Save xorg.conf using Ctrl-O and then exit nano using Ctrl-X
    • Press Alt-F7 to return to X-Windows
  7. X-Windows will still be messed up so press Ctrl-Alt-Backspace to restart it
  8. You should now have a correct looking desktop so just double-click on the ‘Install’ icon to get going

References:
How to install Ubuntu 6.10 in Microsoft Virtual PC 2007

Inline Email Images with CDOSYS

I wanted to send out HTML formatted email with the logo for the company attached to the email rather than referenced to an external URL. Sending attached images like this and referencing them from within the HTML was fairly straightforward using CDONTS with ASP; you just need to use AttachUrl.


set objMail = CreateObject(”CDONTS.Newmail”)
objMail.From = “info@domain.com”
objMail.To = “someone@recipient.com”
objMail.subject = “Your Order Number: 1234″
objMail.BodyFormat=0
objMail.MailFormat=0
objMail.AttachUrl Request.ServerVariables(”APPL_PHYSICAL_PATH”) & “images\logo.gif”, “mylogo.gif”
objMail.body = thisMsg
objMail.send
set objMail = nothing

and then in the body of the email you just have:


<img src=”mylogo.gif” alt=”My Logo” width=”546″ height=”64″>

However, sending an inline, attached, image using CDOSYS is less straightforward but after quite a bit of Googling I found an answer:


set objMail = CreateObject(”CDO.Message”)
Set objMailConfig = Server.CreateObject (”CDO.Configuration”)
objMailConfig.Fields(”http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “mail.domain.com”
objMailConfig.Fields(”http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25
objMailConfig.Fields(”http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2
objMailConfig.Fields(”http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”) = 60
objMailConfig.Fields.Update
Set objMail.Configuration = objMailConfig
objMail.MimeFormatted = true
objMail.From = “info@domain.com”
objMail.To = “someone@recipient.com”
objMail.Subject = “Your Order Number: 1234″
Set objBodyPart = objMail.AddRelatedBodyPart(Request.ServerVariables(”APPL_PHYSICAL_PATH”) & “images\logo.gif”, “mylogo.gif”, CdoReferenceTypeName)
objBodyPart.Fields.Item(”urn:schemas:mailheader:Content-ID”) = “mylogo.gif”
objBodyPart.Fields.Update
objMail.HtmlBody = thisMsg
objMail.Send
set objMail = nothing

then in the body of the email you have:


<img src=”cid:mmlogo.gif” alt=”My Logo” width=”546″ height=”64″>

The key here is the ‘AddRelatedBodyPart’ method which creates a new part to a multipart Mime formatted message. This method has 3 parameters:

1.The physical location of the file you want to attach to the email
2. An arbitrary name you give to the file for reference. This is used within the HTML body of the email to refer to the attached file.
3. Either, a value of zero to indicate that the reference name you gave to the file is in the CONTENT-ID Mime header or a value of 1 to indicate that it is in the Content-Location header.


Set objBodyPart = objMail.AddRelatedBodyPart(Request.ServerVariables(”APPL_PHYSICAL_PATH”) & “images\logo.gif”, “mylogo.gif”, CdoReferenceTypeName)

In addition to the AddRelatedBodyPart method you also need to add a ‘Content-ID’ header to the body part which has a value of the reference name you set for the file.

objBodyPart.Fields.Item("urn:schemas:mailheader:Content-ID") = "mylogo.gif"

References:
http://support.jodohost.com/showthread.php?t=7692

Thunderbird - Filtering and the From Address

I forward all my email addresses to GMail and then download them from there via POP. In Thunderbird I then filter the email according to the To: address and move it to the relevant account.

In Thunderbird 1.07 when I replied to email then the From: address was always set to the correct address for the relevant account. After upgrading to 1.50 the From: address was always set to the address where the mail first arrived in Thunderbird i.e., my GMail account. I could always select the correct From: address out of the dropdown list but I kept forgetting and replying to email with a From: addresss of my Gmail account.

A bit of searching on Google Groups found the post ‘Extensions for Multiple Identities‘ where one of the replys found a solution by editing the ‘C:\Program Files\Mozilla Thunderbird\chrome\messenger.jar’ file. The solution is to edit mailCommands.js within messenger.jar to comment out the following lines:

//if (accountKey.length > 0)
//{
// var account = accountManager.getAccount(accountKey);
// if (account)
// server = account.incomingServer;
//}
In the Google Groups message it states that this code is on lines 250-253 of mailCommand.js but in mine they were lines 213-215.

To edit this file you need to take a couple of copies of ‘messenger.jar’. Keep one as a backup and then open the other using an unzip program - rename it to messenger.zip if necessary - this will extract a folder named ‘content’.

In the unzipped contents find ‘content\messenger\mailCommands.js’ and comment out the lines as described above. I commented out the whole ‘if block’ rather than just the lines inside it. Finally zip up the ‘content’ folder again, rename it to messenger.jar and copy it back over ‘C:\Program Files\Mozilla Thunderbird\chrome\messenger.jar’ - making sure you still have another copy of the original file just in case…

After recreating messenger.jar using Winzip it was only 855 KB rather than the 2,594 KB it was before editing but this didn’t seem to matter - it looks as though the re-zipped file is just in a binary zip format whereas the original jar file was in some other less compressed format.

Thunderbird 1.5 now works in the same way 1.07 did previously. It was nice to find a solution - I was prepared to downgrade to 1.07 if necessary - but this should really be in the UI I guess; someway of choosing the default ‘From:’ address for an account.

SQL Server Express - Exporting Data

Today I set up SQL Server Express with SQL Server Management Studio Express (SSMSE). This was in the hope that it would allow me to connect to a remote SQL Server 2000 instance belonging to a client who has been passed on to me.

As it happens there is no problem connecting to a remote server but there was a problem when it came to my wish to transfer the remote database to my local machine so that I could create a development environment. There is no export facility in SSMSE.

My solution in the end was to:

  1. Use SSMSE to script the remote database - right click on the database and select ‘Script Database as CREATE to file’ - give the output and filename and save it.
  2. In SSMSE connect to your local SQL Server Express instance and create a local database with the same name as the remote one. Set Compatibility Level to SQL Server 2000 if required
  3. Open and then execute the CREATE database script against this new database. This creates all objects in the database locally.
  4. Create a linked server in SSMSE and connect it to the remote server. After a bit of trial and error I found that the correct setting on the ‘Create a new linked server’ properties sheet was to set ‘Server Type’ to ‘SQL Server’ rather than ‘Other Data Source’ and to put the remote server name in the ‘Linked Server’ textbox. On the security tab select the radio button labelled ‘Be made using this security context’ and enter the username and password for the remote server. Click OK.
  5. It is now possible to retrieve data from the remote server using SELECT FROM [remoteserver].[databasename].[dbo].[tablename]
  6. To transfer the data from the remote to the local server I used a series of INSERT/SELECT queries e.g.,
    SET IDENTITY_INSERT [dbo].[tablename] ON
    INSERT INTO [dbo].[table]
    (
    [ID],
    [field1],
    [field2]
    )
    SELECT
    [ID],
    [field1],
    [field2]
    FROM [remoteserver].[databasename].[dbo].[tablename]

I built the SELECT/INSERT queries by cutting/pasting and editing from the CREATE database script I created earlier.

Obviously this is a bit long winded but it was all done with freely available tools and cost me nothing except time. However, time is money and I’ll probably buy SQL Server 2005 developer edition at around £50.00 (GBP) which would have allowed me to quickly transfer the whole database in one go from the remote to the local server

Timesheet.php

I have been having a go at setting up Timesheet.php which, as it name implies is a PHP/MySQL timesheet application.

First of all I had to set up PHP 5 and MySQL 5 on our Windows 2000 box. One or two things to check here -in PHP.ini set the following:

extension=php_mysql.dll
cgi.force_redirect = 0
short_open_tag = On

The last item here was a real gotcha for me because Timesheet.php uses short tags which means it doesn’t work properly at all unless this is set.

Also, make sure IUSR_machinename has execute permissions to the php/ext directory and  libmysql.dll

Once I had PHP/MySQL working it was time to move onto setting up Timesheet.php. The first thing to note is that ‘install.sh’ is designed for  use on a unix box. For Windows you’ll either have to interpret the script or (after I’d already done that) you can just follow the instructions in ‘install.txt’ - Doh!

ASP.Net Calendar Control and XHTML

Having rewritten the Meetings Calendar plugin on the website using the ASP.Net Calendar control I was feeling quite pleased with myself because it used less code and just worked ‘out of the box’ and also looked good. The previous ASP plugin generated the calendar manually as it were.

However, it turns out that the Calendar Control is not XHTML compliant and fails checking on the W3C validator because it uses e.g., ‘Center’ rather than ‘center’ and so on. For now I have reverted to the original plugin. If I find time one day I’ll try to do something about it.

Http Compression and an unknown problem

I have been using the FlatCompression DLL to do Http Compression on our web server. This compresses all textual content sent to the client’s browser to speed up the download. Web browsers have supported compressed content since around 1998. The browser request indicates whether or not compressed content is acceptable - if the request isn’t made compressed content isn’t sent so no harm is done.

The FlatCompression DLL is installed as an IIS wide ISAPI filter but can be turned off on a site-by-site basis by adding a custom header of:

Flatcompression-control:no-compress

When I installed our first Immediacy.Net site I was forced to turn off FlatCompression for that site because the compression was preventing proper retrieval of pages. Just lately I have been installing some more Immediacy.Net sites and it seems that the problem has resolved itself.

Since that first installation I have upgraded Immediacy from version 5.01 via several patches to 5.11 so maybe the problem was in Immediacy itself. Other compression filters are reported to have problems with webresource.axd so perhaps the problem here was with Immediacy’s implementation of this. As I understand it webresource.axd really belongs in the .Net Framework 2.0. At present Immediacy are mimicking it under a .Net 1.1 environment. Maybe their earlier implementations were buggy and the latest one isn’t.

I have now turned FlatCompression back on and all seems to working fine. However, I’m kicking myself for not having kept a detailed record of what the problem was in the first place - just in case I’m mistaken and all isn’t fine at all…

A Blog has to start somewhere…

I’ve decided to start a blog where I can keep a note of technical problems encountered and solved and how, why and when I solved them. I suppose this might include code snippets, links to other sites where I found the solution and so on.

I’ve been thinking of doing this for a while but was inspired by a visit to Helen’s Techblog. She has written her own blogging script but pointed me in the direction of the Open Source WordPress blogging and CMS application which is written with PHP and MySQL - so here I am.