email.heick.email

Yays!

Today i’ve done it. I’ve acquired my email dream!

I’m talking about a nearly-automated @heick.email

…to explain…

For years, if you ever wanted to send me an email I would say:

“Just put your name at the front of @unliterate.net, and i’ll get it.”

Ever since I setup my email @unliterate.net wrong as a catch-all SPAM domain, I’ve had to deal with the following rigmarole when getting new email setup:

  1. Get the name@unliterate.net figured out
  2. Setup a folder in Thunderbird, my email client
  3. Setup a mail filter rule in my email client to move the received message from my Inbox to that folder

Which things have been working for years, and it’s been a fairly straightforward approach.

Until I got married, and we decided to get the heick.email domain and have all our mail shared.

…how to share the email…

So, the @unliterate.net experiment utilized POP3 as the server for me to get all my catch-all. This was easy to configure, and was fairly straightforward.

We needed to be able to share email across computers and devices, though, and still have the flexibility to do the “folder structure”-thingy that I’ve grown comfortable with the @unliterate.net “mail filter” rules.

So, the only solution is to go from POP3 to IMAP.

IMAP gives us the flexibility of folders on the server, not on the client. It also stores all the mail there, and the protocol (after swallowing that it’s not like POP3) is actually quite orderly and simple.

So, i’ve employed dovecot as my IMAP server, which was also my POP3 server, and configured it simply to enable IMAP and know where I want my users mailboxes to be stored.

After setting up DNS for mail, i’ve got email coming into @heick.email, and I’m happy.

I just need to be able to now do the mail filtering…

How to automate folder-making for IMAP

This was a basic challenge, and I love challenges.

I had to use my programming language of choice (PHP) with the php-imap module loaded, and fancy up a script that runs on a */1 (1 minute) cron task.

The script is as follows:

<?php
/**
 * The whole purpose of this script is to perform the following:
 * 1) Open an IMAP connection to an INBOX
 * 2) Look through all the messages
 * 3) Grab all messages and look for the first "To: " header in each message
 * 4) If the person in the "To: " is in the allowed domain
 * - We grab the user
 * - We check to see if their is a mailbox for that user, and move the messge there
 * - We delete the message
 * 5) If the person is not in the allowed domain
 * - We move the message to a default folder
 */

function get_imap_folders($resource, $config)
{
 // Get a list of mailboxes
 $original_folders = imap_listmailbox($resource, "{" . $config['server'] . ":" . $config['port'] . "}", "*");
 // these come through as {server:port}mailbox, so we just clean them up a bit
 $new_folders = array();
 $to_remove = "{" . $config['server'] . ":" . $config['port'] . "}";
 $folders = str_replace($to_remove, "", $original_folders);
 return $folders;
}

$config = array(
 'server' => 'localhost',
 'port' => '143',
 'username' => 'redacted',
 'password' => 'redacted',
 'folder' => 'INBOX',
 'spam' => 'SPAM',
 'debug' => true,
);
$debug_message = "";

$res = imap_open("{" . $config['server'] . ":" . $config['port'] . "/service=imap/novalidate-cert" . "}" . $config['folder'], $config['username'], $config['password']);
if (!$res)
{
 if ($config['debug'])
 {
 $debug_message = "IMAP Stream Failure";
 }
 die($debug_message);
}

$folders = get_imap_folders($res, $config);

// Lets get all the mail messages in the $config['folder']
$mbox = imap_check($res);
$number_messages = $mbox->Nmsgs;
if ($number_messages == 0)
{
 if ($config['debug'])
 {
 $debug_message = "No Messages";
 }
 die($debug_message);
}
$range = "1:" . $number_messages;

// now, we'll get the messages
$messages = imap_fetch_overview($res, $range);
foreach ($messages as $msg)
{
 $msgno = $msg->msgno;
 $to = $msg->to;

echo "Message: " . $msg->subject . "\n";
 if (strpos($to, "@"))
 {
 $array_to = explode("@", $to);
 $to = $array_to[0];
 }

// do we need to create a folder to move this message into?
 $destination_mbox = "{" . $config['server'] . ":" . $config['port'] . "}" . $to;
 if (!in_array($to, $folders))
 {
 if (imap_createmailbox($res, $destination_mbox))
 {
 echo "> Created folder [$to]\n";
 }
 else
 {
 echo "> Failed to create folder [$to]\n";
 }

}
 $folders = get_imap_folders($res, $config);
 if (imap_mail_move($res, $msgno, $to))
 {
 echo "+ Moved successfully\n";
 }
 else
 {
 echo "- Failed to move message\n";
 }
}
imap_expunge($res);
imap_close($res);
?>

To explain, basically this access my IMAP server, gets all the folders, then gets all the mail. It goes though the “to:” portions of the email addresses and sees if I have a folder that matches what’s in the name part of the email address in the “to:” portion. If it doesn’t exist, it makes the folder. Then, as a final result, it moves the mail to that folder and aborts.

So, this script now runs every minute, checking for new mail, creating the folders necessary and moving the messages.

vivre heick.email!

New Years Resolutions!

Another year, 2015, has gone by!

I have therefore created my LONG, LONG list of new years resolutions:

  1. Get a bit of a daily workout. Specifically, moving arms and legs.
  2. Oral Hygiene needs improvement from once a day to twice a day.
  3. Learn to sing “In Tune”.
  4. Clearing my credit report.
  5. Digitally Archive my memories, pictures, documents, etc, so I can feel comfortable in forgetting.
  6. Try to take over the world.

 

And much like last year, I’m hoping to accomplish most if not all this list.

Eventfully progressive Saturday

Today was…

well..

a very nice Saturday.

It seems that once you start doing one thing you end up doing other things that are somewhat “related”, so you accomplish an amazing amount from the start of one little thing.

It started off with E-Mail. After using Windows Live Mail 2011 for so many years, I had finally got sick of it’s inability to help me actually SORT emails into many, many folders. It took me a matter of 45 minutes to extract, re-import, and re-sort out all my mail into Thunderbird, and then completely obliterate Windows Life Mail. I’m fucking happy beyond belief now.

After this, and during peeks at the selected “Pirates of the Caribbean” Marathon I was actually able to properly configure wordpress so I don’t have to download updates and new shit (since I was a retard at the start in setting it up). After aliasing things and getting permissions setup, I’m happily updated as well.

Finally, I’m overly excited at today being my last day of the Stage 1 Nicotine Patch (21mg, 6 weeks). Tomorrow I can start the Stage 2 for 2 weeks, and follow that with the Stage 3 for 2 weeks. I do have yet to still purchase the Stage 2 patch as I’ve already accidentally purchased the Stage 3 on the third week of the Stage 1. Regardless, my wall is getting full and only has 4 more rows remaining after today.

 100_1474[1]

Ramblings…

Time to finally try to eat a pizza. Gotta remember to get one ordered.

I’ve decided on my two goals for 2015. They seem pretty huge and seen far out, but that is what goals are for anyways:

Goal 1: Clear myself of financial debt

This might not be as easy as it sounds. I have to be extra, extra special frugal and heavily track expenses. I’ve already quit smoking and taken in roommates. I do know that at this point, there are 6.75 months of the year remaining, and as long as I keep my job that’s 50% of my salary for the remainder of the year that could cover all of that as payback.

Goal 2: …i have to remember this

I DID know what this was, and now suddenly forgot. I don’t know if the goal was to remember more or not, but there was a legit hard-ass Goal #2.

Choice

Is exactly that, a choice. Mainly, people who are offended by things they choose to be offended by things. People who like/dislike? Choice. Hugging/Kissing vs Life decisions? All choices. We are born, raised, and die by choices. Make the right choices and your good to go. The wrong ones will only put you down if you choose to have them do that to you.