Just out of curiosity, I wondered how often visitors of my blog copy text (especially code fragments) to their clipboard. Detecting copy/paste/cut events in jQuery turns out to be easy And thanks to Google Analytics event tracking API, tracking these events with GA is also easy. This resulted in the following mini jQuery plugin:

 * jQuery Clipboard tracking plugin

(function($) {    
  $.fn.ga_track_clipboard = function() {    
      return this.each(function() {
          var text = $(this).text().substr(0, 10) + "...";
          jQuery(this).bind('cut copy paste', function(e) {  
          // The specification for the _trackEvent() method is:
          //_trackEvent(category, action, opt_label, opt_value)
          _gaq.push(['_trackEvent', 'Clipboard', e.type, text]);

(I will notice it if you copy the code above) 😉

Usage example:

jQuery(document).ready(function() {

Note that this code uses the first 10 characters of copied text as the event label. I don’t think that this an ideal value for the label, but I haven’t come up with a better and generic idea yet.

See also:

Parsing .eml files in C#

December 15th, 2010

I’m experimenting with importing a set of .eml files (each .eml files containing a raw email message) into a SQL database.

Producing the .eml files from an IMAP account is easy. I experimented with different tools

All of these tools are ideal for mail backup and to their job well.

Now, suppose we have a bunch of .eml files produced by one of the above mentioned backup tools. What can we do with them?

First of all, the tools that produce .eml backups, can also restore your e-mail by uploading the backed-up messages back to your IMAP account. But maybe you don’t want to store your mail backup in separate files, or encrypt the raw messages, or …fill in specific wish here... In that case you’ll want to parse the raw .eml files in your favorite language (I’ll assume here that that is C# 😉 ) so that you can do something useful with the different parts (subject, body, attachments, etc.) of the messages.

Although the .EML file format itself is not complicated (the content of an .eml file is the literal content of an e-mail message as received by a SMTP server), interpreting the content, especially MIME content, is not that easy.

Fortunately, Microsoft already implemented mail parsing for us. The method below shows how to parse a single .eml file:

protected CDO.Message ReadMessage(String emlFileName)
    CDO.Message msg = new CDO.MessageClass();
    ADODB.Stream stream = new ADODB.StreamClass();
    stream.Open(Type.Missing, ADODB.ConnectModeEnum.adModeUnknown, ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified, String.Empty, String.Empty);
    msg.DataSource.OpenObject(stream, "_Stream");
    return msg;

(original code from this stackoverflow topic).

You’ll need to reference the Microsoft CDO for Windows 2000 Library, which can be found on the ‘COM’ tab in the Visual Studio ‘Add reference’ dialog. The CDO library is included in IIS.

Read more

Link dump 01.12.2010

December 1st, 2010

Selection of articles/sites that I have found useful/interesting in the past weeks.


Simple JavaScript Namespaces
Describes lightweight alternative for Namespace.js


Usages for the HTTP head request
Blog post by Dean Hume
Announcing the ASP.NET MVC 3 Release Candidate
I’m developing with ASP.NET MVC since version 1 and just started building sites with MVC 2. And now there is version 3 already!
Implementing a custom dynamic object
Blog post by Thomas Levesque
Combine, minify and compress JavaScript files to load ASP.NET pages faster
Blog post by haled Atashbahar
Using Expression Trees and Lambda Expressions to perform CAML queries – Part 1
Blog post by Johan Leino, about custom expression tree parsing for CAML queries.