REALbasic University Resources:

RBU: Glossary Defines common REALbasic programming terms
  Archives Previously published columns
Translations: Dutch Courtesy of Floris van Sandwijk
  Japanese Courtesy of Kazuo Ishizuka
  Chinese Courtesy of Dong Li
  RBU Translation Guide Information on Translating RBU into other languages
Books: Matt's Book (2nd Edition!) Ideal for experienced programmers
  Erick's Book Best for beginning programmers
Websites: Mother Ship The publisher of REALbasic
  RB Webring Links to hundreds of REALbasic websites
  RESExcellence Another REALbasic programming column
  REALbasic Developer Magazine The premiere source for REALbasic instruction.

REALbasic University is Sponsored by

Make your Mac do what YOU want it to. Create games, utilities, cool Mac OS X tricks. Download REALbasic now and create your own software.


Print This Article

REALbasic University: Column 050

SpamBlocker: Part I

This week we're going to start on a simple but extremely useful utility. Those of you who own or create web pages are probably aware that if you include an email link on your website, sooner or later some slimy person will grab that email and use it to send you unsolicited email. In short, you'll get spammed.

Spammers don't actually visit your site personally, of course. They need to harvest millions of email addresses. So they send out software robots that search the web for foolish people who publish emails on their websites.

Of course, if you don't publish an email address, it's difficult for people who you want or need to get a hold of you (like customers) to do so. So what's the solution?

Some people solve this by putting extra stuff in their email addresses like marcREMOVEME@rbu.com. The email address won't work until you remove the "REMOVEME" text. Others write out the email in words: marcatrbudotcom.

Those are poor methods, however: I doubt my mom wouldn't bother with the effort of figuring out how to send you an email. You're practically guaranteed to lose customers if you try those systems.

There are some complicated solutions involving Javascript, but we're going to look at a much simpler method that helps obscure your email from spambots.

Some clever HTML experts figured out that web browsers are designed to convert special characters first, before they process the HTML. Therefore, if you encode your email links as HTML special characters, the spambots, which are looking for "mailto:" references, won't find any on your pages.

HTML 101

For those of you who use WYSIWYG HTML editors and aren't comfortable with raw HTML codes, a bit of review might be in order.

Briefly, to make an email link on a website, you enclose the text you want to be the link with anchor tags with an href (hyperlink reference) pointing to your email address. It looks like this:

 <a href="mailto:marc@rbu.com">Click here to send me mail.</a> 

What we want to do is obscure this by encoding the portion in quotations as HTML character entities. An HTML character entity is either the ASCII number of a character or the name of a character, enclosed within an odd group of letters.

For example, the copyright symbol can be written as either of these:

 &#169; or &copy; 

An HTML character entity is always preceded by an ampersand and ended by a semicolon. If you're specifying a character by ASCII number, precede the number with a number sign.

So if we replace all our "mailto:" text with & and ; gibberish, the spambots won't be able to tell we've hidden an email link on our web page! But web browsers will still be able to read the link and from the reader's perspective, it will work normally.

SpamBlocker Design

There are a number of web pages and freeware programs that will use the system specified above to convert an email address for you. The way these usually work is you type in an email address and it will convert it to HTML gibberish which you can copy and paste into your HTML file.

That's pretty cool, but if you need to convert more than a handful of emails or a few pages, it's a lot of copying and pasting.

This was my situation as I was setting up the REALbasic Developer website. There were a number of different email addresses (corresponding to different departments and people at the magazine) and multiple pages. The thought of copying and pasting all that HTML was depressing.

Immediately, I thought of REALbasic. How hard could it be to create an RB program to do all that work for me? Even better, I decided my program would work more efficiently: with it, you could drop a whole bunch of HTML files and it would convert all the "mailtos" in all the files in seconds!

I fired up REALbasic and in less than ten minutes I had SpamBlocker working. A few extra minutes of polishing and bug fixing, and I was using my little program for real work!

Is it any wonder I love REALbasic?

The Interface

This is SpamBlocker's wonderful, intuitive interface. Obviously, it could be made considerably prettier, but remember I did this in ten minutes. ;-)

To create this, I started a new project and dragged a staticText onto Window1. I put checked the "multiline" option on the Properties palette and added some instructional text. (This is surprisingly important for a simple "interfaceless" application like this. When you come back in six months, you'll wonder how to use it.)

This is really all the interface SpamBlock needs, since it's only going to accept file drags.

The Code

The first thing we need to do is tell Window1 to accept file drags, so we go to Window1's Open event and put in this:

  
me.acceptFileDrop("text")

Since we haven't defined the file type "text" we must do that before we forget. Go to the Edit menu and choose "File Types..." and in the dialog, click "Add..." and fill it in like the graphic below.

What does this do? It just tells REALbasic what kind of file "text" is (it's a text file). Since we've told Window1 to accept file drops of that type, a user won't be able to drop a graphic or application or Word document on the window.

(If we just accepted every kind of file, you'd have to manually check the types and put up an error dialog for invalid files. This way the incorrect file will just "bounces back" when the user attempts to drag it in.)

So, what happens when one or more files are dropped on the window? Well, those files are sent to the DropObject event. Let's go there and add some code on what to do with the files.

  
while obj.FolderItemAvailable
parseFile(obj.folderItem)
if not obj.nextItem then
exit
end if
wend

beep
msgBox "All done!"

Simple, isn't it? The obj object is a DragItem. A DragItem can contain more than one thing (like several folderItems), but you can't access them willy nilly. Basically, obj initially points to the first item. When you call obj.nextItem, it returns true or false, depending on if there are more items. If there are more items, obj is set to the contents of the next item.

So to grab several items, you must either memorize each item as you look at it, or process it immediately. In our case, we're doing the latter.

First, we check to see if there is a folderitem available (by checking obj.FolderItemAvailable). If there is, we're in a while-wend loop. The loop will repeat while obj.FolderItemAvailable is true, so that means until there are no more folderItems inside obj.

Next, since we know we've got a folderItem inside the DragItem object, we can do something with it. Rather than include our processing code here, we'll create a separate method to do the real work. For now, we just go ahead and put in the method's name and send it a file (a folderItem). Our method is called parseFile so parseFile(obj.folderItem) will call it.

After we've processed the file, we check obj.nextItem to see if there's another file. If there's not, we call exit, which kicks us out of the while-wend loop. (If there is another file, the loop just repeats and processes the next file.)

When we're out of the loop, we're done, so we beep and put up a message to that effect.

As I said, simple.

No source file this week, as there's not much code yet. We'll finish this next week and I'll give you the complete REALbasic project file.

Next Week

We finish SpamBlocker.

News: REAL Software's Cubie Awards

Like they did last year, REAL Software is again sponsoring the Cubie Awards for great achievements with REALbasic. Winners receive free REALbasic upgrades and other prizes.

The contest ends April 26, 2002, so everyone needs to nominate their favorite REALbasic software in each category before that date. To nominate someone, or some product, send email to nominations@realsoftware.com. Don't be shy, either. Nominate yourself! (Keep in mind this isn't a vote; stuffing the ballot box isn't necessary.)

Products must be created in REALbasic and be Premier partners in the Made with REALbasic program. The entries will be judged on quality, fitness to the task (fun game? useful utility?), polish, verve, and brio.

Each winner in the nine categories (Advocate of the Year, Cross-Platform, Developer Tool, Game, Internet, Mac OS X, Utility, Overall, and Business) will receive prizes.

The Categories:

Mac OS X: The best application for Mac OS X. It need not fall into any particular category, and can also support the classic Mac OS (and heck, Windows too). Business: The best tool for conducting some sort of commercial activity, whether it is a traditional business application or a tool for creating stuff that makes money for the user.

Game: The best game. We will know it when we see it, can be pure entertainment, action, strategy, educational, you name it, it's all good.

Internet: Best tool for the Internet. This could be anything useful in that rather large arena, from a server tool, to a decoder, player, testing tool. If it uses IP (or its cousins) or some known protocol or format, it's in!

Cross-platform: The best example of an application that embraces both the Mac OS and Windows.

Utility: The best application that does something useful. This too is intentionally broad! All it has to do is crank out the utiles, and we will be all over it.

REALbasic development aid: This includes plug-ins, classes, modules, frameworks, pre- and post-processors, anything that helps some REALbasic developer get the job done.

Overall: The very best REALbasic application we receive. It can be a double winner, or it can be one of those None of the Above fliers that just blows us away.

Advocate of the Year: Finally, there's a special category for the REALbasic advocate of the year, that person who has done the most for the community, and helped make REALbasic known everywhere as the truly great tool that it is.

Letters

This week, Steen writes with a follow-up about RBU 023.

Hello

I have read some of your fantastic column about Realbasic, and especially column number 023.

I was glad to see how we use LittleArrows for numbers.

But how about letters?

After several hours I had to give up, and ask for help. But before I printed this mail I did a search for it on the net. But I did not find much of interest.

My question is simple: How do we replace the number with letters in LittleArrows? (only 1 letter at time)

I'm looking forward for your answer.

Best regards

Steen Horjen

While I'm not sure exactly what you're wanting to do with this, the principal of advancing letters is exactly the same as for numbers. In fact, letters are numbers, from the computer's point of view.

The major difference between making a LittleArrows control that advances/decreases a letter instead of a number, is that there are a finite number of letters, so we must add a check to make sure we don't outside the appropriate range.

The second difference is that we no longer use val() to convert the text to a number: instead we use asc() which returns the ASCII number of the letter. (Note that this only works for a single letter, not a string.)

Here's the revised code for the Down event of a LittleArrows control (it assumes you've got a staticText with a single letter A to Z as the text):

  
dim n as integer

n = asc(staticText1.text)

if keyboard.optionKey then
n = n + 10
else
n = n + 1
end if

if n < asc("A") then
n = asc("Z")
end if
if n > asc("Z") then
n = asc("A")
end if

staticText1.text = chr(n)
staticText1.refresh

Once we've got the current letter's ASCII number, we can increment or decrement that as appropriate. Then we just check to make sure it's within range (I've arbitrarily decided to limit it to capital letters in the range A to Z for this example, but you could limit it any way you wanted). Note that I've made it "wrap around" -- if the person goes above A the next letter is Z, and below Z is A. As a user, I always prefer that as a shortcut versus having to click the down arrow 26 times to get to Z.

The Up event is just like this, except it subtracts instead of adds.

I hope that helps you, Steen!


About the Column
REALbasic University is a weekly instructional column on programming with REALbasic and is brought to you by REALbasic Developer, the magazine for REALbasic programmers.

Each week we answer select reader questions, and we're always open to ideas for future columns. Send your questions to . (Keep your questions simple and specific. General queries like "How do I write my own web browser?" will be neglected.) Your question won't be answered immediately, but will be answered in a future column. (If you don't want your correspondence published, just be sure to indicate that when you write. Otherwise it's fair game.)

About the Author
is an author, philosopher, graphic designer, photographer, film director, soccer fanatic, and programmer (among other things). He writes for MacOpinion, runs his own software company, Stone Table Software, which sells the revolutionary Z-Write word processor, and is Publisher and Editor of REALbasic Developer. He lives in Northern California with his cats, Mischief and Mayhem, and is rapidly running out of free time.

See the REALbasic University Archives


REALbasic University contents ©2001-2004 by Marc Zeedar and REALbasic Developer. All Rights Reserved.

Email This Article - Comment On This Article

.

Reader Specials

Server Racks Online:
Apple Xserve CompatibleServer Racks and Universal Network Racks
42U KVM Switch Solutions:
High-End Mac and Multi-Platform KVM Matrix switching solutions!
Digital Camera Online:
Great prices on Digital Cameras and accessories!
KVM Switches Online:
Great prices on Mac KVM Switches from the leading manufacturers!
LCD Monitors Online:
Great prices on LCD Monitors from the leading manufacturers!
LCD Projectors Online:
Shop online for LCD Projectors from the leading manufacturers!
USB 2.0 Online:
Great prices on USB 2.0 products from the leading manufacturers

Serious Business Software:
Accounting, Sales, Inventory, CRM, Shipping, Payroll & more!

KVM Switch solutions for MACs:
DAXTEN is a KVM switch, KVM extender and monitor splitter specialist for PC, SUN and MAC applications from name brand manufacturers - offices worldwide.

The "Think Different Store: The iPod Accessories Store - iPod cases, iPod mini, iPod photo, speakers, itrip, inMotion, Soundstage and all other iPod accessories

Earn Cash with the ThinkDifferent Store Affiliates Program

Need A Web Site?
Applelinks Web Hosting Starting at 19.95 a Month

iTunes_RGB_9mm

.

iTunes_RGB_9mm

Cool Mac Gear


iPod 1G-2G
iPod 3G
iPod 4G
iPod Mini
PowerBook-iBook
Keyboard Skins
Garageband