mailReader.php — Parse E-mail and Save Attachments PHP, Version 3

mailReader.php version 3 is here!

mailReader.php is a PHP script which handles incoming email messages, saving attachments to disk, and logging emails to a database.

Download it from GitHub now:  https://github.com/stuporglue/mailreader

E-mail Processing Script Features:

  1. Saves the e-mail sender, subject and body to a database
  2. Saves any attachments as files and creates an entry for those files in the database, associated with the e-mail info in #1
  3. Sends  a response back to the sender telling them what files were received and their file sizes
  4. Checks a list of allowed senders to make sure we only take files from specified addresses.

Improvements in Version 3

mailReader.php is growingup a little bit more. It’s now a class instead of just a script. A new script mailPipe.php uses the mailReader class to achieve the same results the script did previously.

I did some database renaming so that none of the fields are reserved names, and they don’t need to be escaped anymore.

I updated the database connection code from mysql_connect to PDO.

I added support for uuencoded attachments. Uuencoded messages don’t have their mime-type detected, but everything else is the same as mime attachments.

Security

Make sure that your upload directory is out of your webroot. If someone emails you a malicious PHP script (eg. Virus.php) and can access it via the web, they could infect your server or your visitors. Many servers are configured to automatically treat .pl and .cgi as CGI scripts and run them as well. You do not want to create a way for untrusted users to upload files to your webroot!

With the file names in the database you can use Readfile to pass files down to users.

Contribute Back!

I welcome any contributions which others may benefit from, so if you hack on it, consider submitting a pull request on GitHub.

Posted in Computers, GitHub, Programming | Tagged , , | 1 Comment

EnterAsTab.js

I was creating a mobile website and pressing enter on my iPad keyboard kept submitting the form.

Here’s the short script I wrote to avoid that problem It’s EnterAsTab.js. It’s pure JavaScript (no jQuery or anything) so there’s no dependencies, although you could use jQuery to refine which elements have the function applied.

EnterAsTab is on GitHub

function enterAsTab(e){
if ( e.which == 13 ) {
        // We’re on a submit, so click it
        if(this.getAttribute(‘type’).toLowerCase() == ‘submit’){
            return; // let default bubble up
        }
        var n,t;
        n = this;
        do {
            n = n.nextSibling;
            if(n === null){ return; }// no next sibling. Do default behavior
            if(n.tagName != “INPUT”){ continue; }
            // don’t deal with things without a type (such as labels or text nodes) or which are hidden
            t = n.getAttribute(‘type’);
            if(t === null || t.toLowerCase() == ‘hidden’){
                continue;
            }
            if(t.toLowerCase() == ‘submit’){
                return; // bubble up to default
            }else{
                n.focus(); // Found one. Focus,prevent default and done
                e.preventDefault();
                return;
            }
        } while(n !== null);
}
}
function applyEnterAsTab(){
    var inputs = document.getElementsByTagName(‘input’);
    for(var i = 0;i<inputs.length;i++){
        inputs[i].onkeypress=enterAsTab;
    }
}

Usage

You can apply it to all <input> field by simply running:

applyEnterAsTab(); // all input elements are now set to use EnterAsTab

If you’ve got jQuery or Zepto already you can do something like:

$('input.enterastab').on('keypress',enterAsTab); // Only the inputs with enterastab class

$("#oneform input").on('keypress',enterAsTab);   // All inputs within a specific form
Posted in Computers, GitHub, Programming | Tagged , , | Leave a comment

I’m the Happy Owner of a Lathe

I’ve been the happy owner of lathe since some time last summer or fall, but now I’m the happy owner of a functioning lathe. My aunt gave me a lathe her friend had. It’s a 1950s or 1960s PowerKraft from Montgomery Ward. It is in really good condition. The paint is a little worn in some places, but there’s no rust, and all the screws turned pretty easily. I oiled it up and it works like a champ.

I’ve wanted a lathe for a long time. You might remember that about 18 months ago I turned my drill press into a lathe. That worked well enough, but I couldn’t turn anything bigger than a fishing lure on it and I didn’t have the right tools.

This lathe doesn’t have a motor, and I don’t have a lot of space. I already had a motor mounted on my work bench to power my (also antique!) grinder so I added some braces where the lathe should go. Now I can slide the lathe in securely and pin it in place.

My aunt also gave me the body of an an old avacado-green juicer or stand mixer. It’s got a 1/3 HP motor in it, which is twice as powerful as the 1/6 HP motor I have mounted here. The mixer motor doesn’t have a table mount though, so I’m going to have to figure out how to mount it one of these days.

The lathe on my bench
The lathe on my bench

Today I went and bought a $60 set of High Speed Steel lathe chisels from Harbor Freight, and picked a straightish piece of wood from the wood pile.

It was pretty fun to see it get rounded out just like the YouTube videos I’ve been watching. I got through the bark and got it nice and smooth.

A Birch Log
A Birch Log

For my first project I decided to do something simple — a kids size rolling pin. It ended up slightly tapered, and the grooves on the handles aren’t symmetrical, and the grooves aren’t as smooth as I would’ve liked, but I thought it went alright for a first project.

A Rolling Pin
“What is this? A rolling pin for ants?”

The final test will be in the morning when the snoozy wakes up  decides if she’s excited about it or not.

Snoozy with a Rolling Pin
Snoozy with a Rolling Pin

 

Posted in Projects, Woodworking | Tagged , , | Leave a comment