Alternate Remote SSH File Edit on Windows with Filezilla and ScITE

Jan
18
2007

A few weeks ago, I mentioned some solutions to allow editing remote files via SSH from a Windows workstation. While I'm still seriously considering buying SFTPDrive for my main development workstations, I ran across another option: this one free.

When I was messing around in Filezilla (my FTP/SFTP client of choice) last night to change the permissions on some files, I noticed an option on the context menu that I'd somehow missed all this time. Right there above "Create Directory", which I've clicked a couple of hundred times in the last few months alone, was "View/Edit".

After digging through the config options, and making ScITE.exe my editor of choice and I can quickly edit files on any SSH server without having to map a drive. To make the best use of this chain of tools, you do need to change the following ScITE setting to "0" instead of 1.

check.if.already.open=0

This is because, when its set to 1, any new file loaded by ScITE will reuse the current open instance. However, because the file we're editing will only get updated when Filezilla detects that ScITE closes down all the way. That would be a problem if you've got other files open. Your changes to the remote file wouldn't be saved without closing all of your open files.

Once you change that setting, Filezilla will open a new copy of ScITE for each file you want to edit. Still only reasonable for more "quick" edits instead of ongoing development. However, better than nothing and offers an option for those on Windows who don't want to pony up the cash for SFTP Drive or just prefer this way of working.

Like I often say, no matter how much you may prefer Philips-head screwdrivers, sometimes the screw or bolt is a hex-head or slot. We use toolboxes instead of just keeping one tool on our belts because the right tool for the job is often different than it was for yesterday's job.

7 Steps to Cleaning Up IMAP Email Inboxes with PHP

Jan
16
2007

I've gotten a couple of emails wondering what's up with my Saved Feed Items page. Over the last month or 2, it's emptied out more than a few times. To understand why, you need to know how that page works in the first place.

I have a periodic cron job that hits my OPML list, retrieves the contents of all 800+ feeds, and converts any new entries into email messages which go to a separate email address.

In that IMAP inbox, they sit, until a POPFile filter or I take a look at them. The POPFile filter moves them into "interesting" and "uninteresting" folders.

I end up looking at both the INBOX (where unclassified stuff stays) and the "interesting" folder for stuff to read.

I read the email account in Thunderbird and use the color-coding keywords to classify the items. I hit the "1" key and it gets flagged in red as something I want to share on the Saved Feed Items page. I hit the "2" key as orange for stuff I read and am planning on deleting. I don't delete them immediately because the delete is much slower than the tagging. This way, I can pretty much cruise through a folder and process it quickly.

I then go back every once in a while (see the problem on the horizon?) and move the red messages to a folder called "publish" and delete the orange ones. The "publish" folder is what the Saved Items page reads when it displays recent items. Enter the problem. Usually, I hit these folders in the "Unread" view, which only shows me the stuff I haven't yet looked at. That means that there can build up a huge pile of red and orange stuff I've read but not moved. This is exactly what's been happening.

When I initially created that page, I took a cursory look for a way to act on the messages based on their color-coding. I knew that, since the colors persist between my machines on that IMAP account, the flags were getting set on the server. However, doing a dump of the information that PHP had on a message didn't reveal any place that they were being stored and accessible to PHP. So, I just went forward with the manual process.

Early this morning, I finally had it and dug around for the real solution. What I found led to a nice little solution to not only the original problem but mailbox cleanup in general.

PHP has a nice little function called imap_search(). It takes this SQL-like query language for searching for messages. One of the parameters that imap_search() takes in is "KEYWORD", which is the color-coding in question. However, since PHP doesn't seem to actually fetch this header (called X-Keywords by the way), I was facing the prospect of being able to search for them, but not knowing what to search for.

So, I logged into the server and took a look at one of the mbx files in question. That's when I saw the X-Keywords header and the values in it. I switched back to PHP to see if somehow I missed that header in my dump of a test message. Nope. It's not there.

That's still irritating, but no longer a roadblock. After looking in the right mbx file, I saw that the relevant X-Keyword values were: $Label1 for the red messages and $Label2 for the orange.

OK. To clean up completely, what I need is to delete all orange messages wherever I find them and move any red ones to a specific folder. The basic procedure for this and all other cleanup stuff is the same. Once I figured it out, I also added one that archives old items out of the publish folder (thus speeding up the Saved Items page).

Here's the basic procedure:

  1. Open a link to the IMAP account and appropriate mail folder.
    $mbox = imap_open("{mail.example.com:143}INBOX", "email@example.com", "password");
  2. Query the folder for the relevant messages.
    This is the query for "red" messages.
    $messages = imap_search($mbox,"KEYWORD \"\$Label1\"");
    This is the query for messages that are older than 7 days. This one's a bit more elaborate because you need a date formatted correctly.

    $end_time = strtotime("-7 days");
    $end_date = date("D, j M Y",$end_time);
    $messages = imap_search($mbox,"BEFORE \"$end_date\" SEEN UNDELETED");
  3. Reverse the array (I do this just to get them in a neat order. This is totally optional.
    $messages = array_reverse($messages);
  4. Loop through the messages.

    foreach($messages as $item){
    }
  5. Inside the loop, do your action.
    To delete the message:
    imap_delete ($mbox,$item);
    To move it to another folder (foldername):
    imap_mail_move($mbox,$item,'foldername');
  6. Expunge the folder. This is because both moves and deletes are actually just flags on the messages. They aren't really deleted until you expunge.
    imap_expunge ($mbox);
  7. Close the mailbox.
    imap_close($mbox);

Going through those steps for each of the cleanup options let me completely organize my inbox automatically. I'm going to tie all of these operations to the script that actually does the fetching. Now, it will cleanup old messages and then move on to getting new ones.

A couple of notes.

Not all IMAP servers support the server-side flags. In those cases, Thunderbird fakes it and stores them on the client side. This won't work with those.

Also, while $Label1 and $Label2 are what I used here, it's because that's what Thunderbird uses (and does so because you can change what red means from "Important" to whatever you want). If you use another email client, this wouldn't necessarily be right.

There's more information on the IMAP queries on the imap_search() documentation page.

Setting Up an OpenID with PHP

Jan
15
2007

One of the best, simple things I ever did online was to register wynia.org as a domain name. Ever since, I haven't needed to worry about *which* email address I used on that site when I signed up. I don't have to have some other company's name as part of my web URL on my resume, and, if you can remember my name, you can find my site and get me email.

Given the pain that went away with having a permanent "home" online, I've been eyeing the OpenID activities with keen interest. While I'm semi-OK with site-specific logins for things like banking and other sensitive data, I'm thoroughly sick of having to create a login for every single forum, discussion group, etc. that I want to participate in or non-critical site I want to use.

OpenID gives you a single URL that you use as your identity on other sites. It's secured with a password. The site you're wanting to use just has you enter your OpenID and they use your OpenID server to authenticate. Next thing you know, you're using the site as "you" without a new account somewhere.

If you're looking to just have an OpenID for yourself and maybe one or 2 other people, phpMyID is a nice, simple solution. I've had installing it on my TODO list for quite a while and finally got around to it last night.

It comes with a core class that you include into each identity that you want the server to handle. The identities are each in their own PHP file, named whatever you want. If you're only going to serve up one OpenID (like I am for right now), you can name it openid.php. Anyone else who wants to use my server will get a similar file, named username.php, etc. I named mine this way to have an easy to remember and nice-looking URL.

At any rate, in the openid.php file, there are a few things you need to change, including the username and the password. However, rather than just storing the password in the file, you actually store an md5() hash that you send in instead.

To generate the appropriate string to use as a password, you need to md5() a combination of things, strung together with colons between them. I just made a one line PHP script that spits out the appropriate value to put into the script.


print(md5("username:phpMyID:yourpassword"));

I put the result of that in as the "auth_password" and set the rest of the stuff to fairly obvious settings. I then put the openid.php file on my personal subdomain: j.wynia.org. So, my new OpenID URL is: http://j.wynia.org/openid.php.

Once you think you've got your OpenID set up properly, you can test it out via the test script at OpenIDEnabled.com. I just gave it the OpenID URL above and logged in without any glitches.

Overall, I like this approach a LOT better than the more centralized models for single account signon because I can control it. It's not going to go away because some startup decided to spend all of their money on massages for employees' pets and went bankrupt.

I still need to integrate the autodiscovery into the site properly, but the test login works, so I'm happy.

I Just Want Tickets, Not to Have My Literacy Challenged

Jan
14
2007

I just finished attempting to prove my literacy to Ticketmaster. My attempts were entirely unsuccessful. Despite 8 . . . separate . . . instances, I was absolutely incapable of providing Ticketmaster with the secret word that was supposedly spelled out in the garbled mess they call a captcha.

So, I guess I won't be going to the Minnesota Swarm game after all. After the news report on the team last night, I was pretty interested in going to a couple of games. Too bad they're using Ticketmaster to handle the tickets because I'm NOT going to try again any time soon.

I just can't believe that they aren't able to come up with a way to prevent automated ticket buying that doesn't require more deciphering skills than reading a doctor's prescription.

Making sIFR Fonts without a $600 copy of Flash

Jan
13
2007

I'm taking yet another stab at redesigning this site, though this time I'm just starting with a template from OSWD rather than from scratch. That's really helping on the graphic design front. However, given that a site like this is primarily text-based, I'd really like to have better font control than HTML usually offers .

That's where sIFR comes in. It uses Flash to do high-quality font replacement in web pages. While it doesn't really work for body text, this would be a way to use something other than the same 4-5 fonts we all end up using for headlines, pullquotes and other accent text.

I've mentioned sIFR before, but haven't ended up implementing it anywhere in production. Part of that was the conversion of a TTF font into the SWF Flash file that sIFR uses to work its magic. The Javascript/HTML part itself is relatively straightforward, but when the instructions for getting the font ready in the first place included launching the full version of Flash, I kind of lost my momentum.

However, now that I'm looking at a redesign, I wondered if there was another way to get the SWF from my existing fonts. Like most problems that exist for very long, there is indeed a solution.

The sifrFontEmbedder is pretty basic. You give it a TTF font file and it spits out the SWF for use with sIFR. You do need to download SWFMill as well, but other than that and sIFR itself, you don't need anything else.

I grabbed the tools and generated a copy of my LetterJ font that worked flawlessly on the test page. If you'd like the SWF, you can just grab it.

Now I can use any TTF font on my system. There are some pretty good candidates that are 100% legal to use this way on the 20 Best Free Fonts list and the fonts under the Open Source Font license are always a good place to start.

« Older Entries   Newer Entries »

J Wynia

For better or worse, I'm the guy who runs things here. I'm a web consultant, software developer, writer and geek from Minneapolis, MN. This site is a fairly wide cross-section of the things I'm interested in and enjoy writing about.

Oh, and if you happen to be looking for hosting for your Subversion repositories or just web hosting in general, take a look at Dreamhost. It's what I use for Subversion and your signup helps me out.

Feeds and Links


www.flickr.com
This is a Flickr badge showing public photos from J Wynia. Make your own badge here.

Search


Pages

Archives

Computers Blog Directory
© 2003-2008 J Wynia. All original content is licensed under the terms of the Creative Commons Attribution license unless otherwise noted. Content from other sources is licensed under its original terms.