Category Archives: Code

MyBook backups with Rsnapshot and some bash trickey

I had a client accidentally purchase half a dozen 500GB MyBook’s instead of the simpler cheaper USB models.

Since this site is remote from me it took a little while to deduce what was going on since the MyBook’s don’t act as USB drives and hence don’t appear as a USB device to linux.

User: ‘Yes, I’ve plugged it in! Yes it’s using the white cable!’
Me: ‘So… what exactly does it say on the box what drive it is…’

Anyhow, after figuring out that is was a MyBook I implemented ssh access using Martin Hinner’s clever hack and found a nice website of various MyBook Hack’s.

I was originally using the venerable Rdiff-backup, but alas couldn’t see it in the Optware packages. So I implemented a Rsnapshot solution, the only problem was I wanted some notifications from the MyBook devices to check that the backups were working, and so a simple bash script was in order…

#!/bin/bash
mailto=[email protected],[email protected]
time=$1
if /opt/bin/rsnapshot $time > /tmp/rsnapshot.log 2> /tmp/rsnapshot.log
then
subject='Backup success'
else
subject='Backup FAILURE'
fi
cat /tmp/rsnapshot.log | /opt/bin/nail -r [email protected] -s "$subject" $mailto

WP-Mail ver 0.311

I had a nice long holiday at Coolangata, Queensland, Australia and had quite a lot of time sitting on the couch as my girlfriend read her book. So I grabbed my Powerbook and slowly worked away on my wp-mail.php plugin! It’s nice to work on something without having to worry about timing and just bang away…

IMG_259.jpg

And that’s a photo of my me lying on the couch, I knew I should have not taught Lauren how to use the camera… :)

Thanks to all the comments and feedback of this hack, because people submit code and fixes it’s a better program for everyone. With a little more work we’ll get this plugin rock steady stable and see if the wordpress dev team would consider it for the core code of wordpress.

Here’s the updates that have happened in the latest version:
- HTML e-mail support added (Thunderbird clients can easily use this mod now!)
- Subject line searching support for categories (i.e., Subject: [Code] WP-Mail, will post to the Code category)
- Added UBB decoding support, so if you want to post things written out of say phpbb you can now
- Direct posting support (using /etc/alias on your e-mail server you can send the
- PHP5 support
- More fixes

What needs to be done is a bit of work for the HTML e-mail support. It works at the moment, but it needs a little more work to add the images in position of where it is in the actual e-mail. At the moment all images in HTML e-mail’s are just attached to the bottom of the message which is probably not what people want. I can do it, just got to figure out the best way.

The second thing I suppose most people want is a little bit more image manipulation (like resizing images). I’m not sure if this should be included in wp-mail.php or have wp-mail.php interface with some other image plugin for WordPress. I’ve played around with thumb nailing

* -= History =-

* Version 0.311 – 2005-01
* – eep, major bug for pop3 server. Next time I test my code more before I released, fixed so that pop3 now works.
* Version 0.31 – 2004-12 & 2005-01
* (Has it been this long, best get back into the swing of things… did most of this coding on my holiday as I didn’t have a machine to play WoW on :)
* – moved the deletion of pop3 emails into a check so that e-mails aren’t deleted without proper checking.
* – added html ‘decoding’ (basic support for Thunderbird & Outlook)
* – updated the Category search so that it matches words as well as numbers (i.e. [General] Subjectname will work instead of just [1] Subjectname)
* – Changed time function from time to strtotime (as per Senior Pez’s suggestion), but found out that strtotime isn’t in default php distro…
*
* Vesion 0.3 – 2004-09
* – Added UBB decoding support
* – Added default title (when there is no subject assigned)
* – Started doing a little code cleanup, been reading Advanced PHP Book :)

Download it and test it out, I’ll be writing a little HowTo on using the direct e-mail support when I have a little spare time, in the meantime enjoy!

wp-mail-0.311.zip

wp-mail mod update! Now 0.2!

Thanks for all the feedback for my last wp-mail mod. I’ve done a lot of bug fixing in this release, and added a few features. Still working on improving though, so let me know how you guys go with this version!

Here’s the new version: Thanks for all the feedback for my last wp-mail mod. I’ve done a lot
of bug fixing in this release, and added a few features. Still
working on improving though, so let me know how you guys go with this
version!

Here’s the new version:wp-mail-0.2.zip

<rip from README-wp-mail.php>
Wordpress 1.2 – wp-mail hack
Released 2004-08-26 – Version 0.2
By John B. Hewitt – [email protected]
Blog: http://blade.lansmash.com

License
-=-=-=-=-=–
It’s GPL! Credits are in the wp-mail.php code.

Introduction
-=-=-=-=-=-=-
This hack is a ‘drop in’ replacement for the current wp-mail.php. It uses pear as a mime compliant email ‘decoder’. What’s cool is that you can attach images inline in your email messages and they’ll be shown as an image in your wordpress article. It does this by decoding the image attachments and writing them to ‘wp-photos’ directory (not in default wp install).

History
-=-=-=-
* Version 0.2 – 2004-08-26
* – Stopped using pear body decoding in favour of own decoding (may be slower but more modifiable) because of enriched text decoding
* – Added base64_decode checking (may help mobile phone users)
* – Fixed Subject line for non-english users (htmlentities instead of just trim)
* – Fixed error in some pop hanging -> more graceful exit on event on no emails in inbox ($pop3->quit)
* – Added work around for email addresses with exta <> in field (ie: <[email protected]> instead of [email protected]
* – Added some ===basic=== enriched text support
* – Updated readme file for easier install
* – Easy modify of globals (such as photosdir and filesdir)
* – Cleaned up some pear stuff in install
*
* Version 0.1 – 2004-06-20
* First release (was released under version 1.0 initially, oh boy was I silly)

Features
-=-=-=-=-
It has all the abilities of the current wp-mail.php plus:
- Allows image attachments (posts inline! Main reason I built this mod!!)
- Checks if user email address is in the database (otherwise discards message)
- Allows other file attachments (zip’s, exe’s, etc)
- You can post to various categories (ie, 1 = General)
- Fairly good cleaner for removing excessive line breaks

Would love to see it in the wordpress core
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
I’m planning on more updates, but would love to see this update included in future wordpress releases. Would be happy to maintain it to, I’m fairly sure it complies with most of the coding guidelines I’ve read on
the wordpress coding standard.

Install
-=-=-=-=-
To install you grab the zip file.
- – Drop the two files (wp-mail.php & mailmimedecode.php & PEAR.php) into your wordpress 1.2 root directory
- – Create the directories ‘wp-photos’ and ‘wp-filez’ in the wordpress root directory (with writing permissions (probably 0777).

That’s it. You should now be able to post email to wordpress.

Features to come
-=-=-=-=-=-=-=-=-
Immediate features to come:
- Direct email script that parses email as it comes in (so removes cronjobs)
- GPG/PGP signature verification
- Better enriched text support (only basic stuff at the moment)
- Better security for file attachments (no .php stuff, less l33t hax0rs)
- Look ups for Category posting

Usage
-=-=-=-
You can use the wp-mail hack just like the old wp-mail.

Make sure you change your email client to use HTML encoded messages, that way you’ll get a better looking post that is similar to what you emailed.

When emailing to your blog you can also change the category the post is going to. To do so change the subject line to include [1] at the beginning where one is the number of the category you want to post to.
1 is usually General’s category, so if I want my email to go to the General board I type:
Subject: [1] This is a test

FAQ
-=-
- If you are using Mozilla (thunderbird,etc), use HTML mail! Not HTML/TEXT combined! (One day this script will be able to decode both at the same time, just not today)
- If you are using Outook/Outlook express, use HTML mail!
- If you are using Mac OS X email, you’re sweet
- You can change the default photos and files directories. The variables are on the top of the wp-mail.php code.

wp-mail.php

Started using WordPress a few days ago and love the clean look/design/code. But it got me thinking about photos, I love photos but hate having to upload stuff and linking to it (CMS style). In fact I’m so lazy, I decided to have a hack at wp-mail.php
What I ended up doing was replacing most of the code in wp-mail.php for wordpress 1.2, didn’t anticipate that when I first started but the results are nice.

This hack is a ‘drop in’ replacement for the current wp-mail.php. It uses pear as a mime compliant email ‘decoder’. What’s cool is that you can attach images inline in your email messages and they’ll be shown as an image in your wordpress article. It does this by decoding the image attachments and writing them to ‘wp-photos’ directory (not in default wp install).

It has all the abilities of the current wp-mail.php plus:

  • Allows image attachments (posts inline)
  • Checks if user email address is in the database (otherwise discards message)
  • Allows other file attachments (zip’s, exe’s, etc)
  • Fairly good cleaner for removing excessive line breaks

I’m planning on more updates, but would love to see this update included in future wordpress releases. Would be happy to maintain it to, I’m fairly sure it complies with most of the coding guidelines I’ve read on the wordpress website.

To install you grab the zip file: wp-mail.zip

  1. Drop the two files (wp-mail.php & mimedecode.php) into a wordpress 1.2 root directory
  2. Create the directories ‘wp-photos’ and ‘wp-filez’ in the wordpress root directory(with writing permissions (probably 0777).

Let me know what you guys think!