Apple Mail gets stuck in a ‘recovered mail’ loop

I had a call today from a client who was having trouble with Apple Mail. Specifically, there was a 25mb email sent to him by a family member that Mail was continually trying to ‘recover’ and send up to his Google Apps mail account. After a bit of googling, the answer was pretty easy, though asking someone to use the ‘rm’ command who’s never used the Terminal.app was a little concerning :)

# Close Mail.
# Open a new terminal window and paste the following:
# ls -la
# Then replace ‘email@domain.com’ with the one that matches the account that’s having issues
# rm ~/Library/Mail/email@domain.com/.OfflineCache

That should fix it.

Setting up Samba share for a vmware OS

Sometimes it’s useful to be able to browse via the file system via a GUI. So on the advice of @AndyGale I installed Samba on my Ubuntu OS instance and created a share for the entire server. The first part of these instructions were from labs.boulevart.be.

  1. open the samba config sudo nano /etc/samba/smb.conf
  2. change “security=user” to “security=share”
  3. comment out “passdb backend = tdbsam” and “obey pam restrictions = yes”
  4. add a line saying “map to guest = bad user”
  5. comment out the lines beginning “passwd program =” and “passwd chat = “

Then we need to add a new share to the conf

[share]
    path = / 
    read only = no
    guest ok = yes
Links for setting up a VMware dev server

Have waded through the net and found these the most useful.

  1. Download VMWare Fusion demo from https://www.vmware.com/tryvmware/?p=vmware-fusion&lp=1
  2. Get the server image you require from http://www.thoughtpolice.co.uk/vmware/#ubuntu8.04
  3. Install using the guide that matches your download http://www.thoughtpolice.co.uk/vmware/howto/1-minute-guide.html#ubuntu8.04
  4. Follow these instructions for installing SSH, VMWare tools http://intranation.com/entries/2009/03/development-virtual-machines-os-x-using-vmware-and/

Now you can set up apache, mysql etc as you would do normally on a VPS or dedicated box, using SSH.

    Clean inputted html with CakePHP BritaBehaviour

    I’ve been using TinyMCE as a text editor in my CMSs, and whilst it’s good, it can lead to the odd empty tag/para ending up in the html, font tags and all manner of other crap (especially if M$ Word has been involved at all), so I created a cakephp behaviour that uses the HTMLPurifier class to make all inputted html valid.

    First, you need to download the most recent version of the HTMLPurifier class from http://htmlpurifier.org/download, drop this in /{app}/vendors, and save the pasted code as ‘brita.php’ in /{app}/models/behaviors/.

    It’s dead simple to use, just do:

    var $actsAs = array(
    	'Brita'=>array('synopsis', 'body', 'extended_body')
    );

    In the model(s) you need to clean up.

    Use MySQL’s SUM function with CakePHP find()

    Saw this on IRC earlier, thought I’d blog it as it’s pretty useful info.

    Add this method to your AppModel:

    public function sum($field='total')
    {	
    	$data = $this->find('first', array(
    		'conditions'=>$conditions,
    		'fields'=>array('SUM('.$field.') AS summed'),
    		'contain'=>array()
    	));
    	return $data[0]['summed'];
    }

    Then call it like so:

    $total = $this->Model->sum('cost');

    Hope this is useful for someone.

    update on find(‘neighbours’) with HABTM

    And, here, to cap off a really terrible brain day, is the solution, using cake’s core functionality, to the find(‘neighours’) with habtm conundrum!

    $this->Mixture->bindModel(array('hasOne'=>array('MixtureCategoriesMixture')), false);
    $this->set('neighbours', $this->Mixture->find('neighbors', array(
    	'field' => 'Mixture.sku', 'value' => $this->data['Mixture']['sku'],
    	'conditions'=>array(
    		'MixtureCategoriesMixture.default'=>1,
    		'MixtureCategoriesMixture.mixture_category_id'=>$this->data['MixtureCategory'][0]['id'],
    		'Mixture.status'=>1
    	)
    )));

    Doh, doh doh!

    Update on find(‘neighbours’);

    After some IRCing, it appears I’d misunderstood how the array should work to get the method working correctly.

    $this->set('neighbours', $this->Species->find('neighbors', array(
    	'field' => 'Species.latin_name', 'value' => $this->data['Species']['latin_name'], 'order'=>'asc',
    	'conditions'=>array(
    		'Species.species_category_id'=>$this->data['Species']['species_category_id'],
    		'Species.status'=>1
    	)
    )));

    What a plonker.