Sunday, 26 November 2017

Commodore 64 Basic

Well, that was a nice trip down memory lane!

I have just come across the C64 Mini over at https://thec64.com. It's not being released until 2018 but it's a mini replica of the Commodore 64 with USB and HDMI ports.

The Commodore 64 was my very first computer. Of course I played the games! Buggy Boy & Commando instantly spring to mind. But the cool thing about the C64 was that it booted up into the basic language! I have fond memories of typing out programs from the back of magazines only for them not to work. The result of a rouge typo somewhere!

But I do remember experimenting with the basic language because the user manuals for the computer covered the BASIC language. Amazingly I have just found the manuals preserved online here.

Isn't it funny that the GOTO keyword is considered harmful today in software development, but it introduced me to scrolling my name infinitely up a TV screen!

10 PRINT "Ocean Airdrop Woz Here"
20 GOTO 10
RUN

Anyway, what I didn't realise at the time was that Commodore Basic was actually licensed from Microsoft. Commodore worked with Microsoft to produce a ROM based version. This was in the early days of Microsoft so their name wasn't mentioned anywhere! However according to Wikipedia Microsoft included an easter egg into the version 2. If you typed:

WAIT 6502, 1

...it would print Microsoft on the screen. There is a great article about this over at the cached version of the defunct site pagetable.com here. It says: "Legend has it Bill Gates himself inserted this easter egg after he had had an argument with Commodore founder Jack Tramiel, just in case Commodore ever tried to claim that the code wasn’t from Microsoft".

Who knows how much of that is true, but who can argue with a sentence that begins with "Legend has it...."

Back to the C64 Mini! Will I get this replica when it comes out?

Nahh... It's probably just a Raspberry Pi in a fancy case. Also, the keys don’t work and are just for show. I guess you do get the joystick though. I think I'll wait for the Amiga version to show up!


Contact Me:  ocean.airdrop@gmail.com

Sunday, 5 November 2017

Reading the contents of emails in an inbox.

The .NET framework comes with a SMTP email client to send out emails in the box and is simple to use:

var msg = new MailMessage("oceanairdrop@gmail.com", toList, subject, messageBody);
var client = new SmtpClient(server).Send(msg);

But recently, I wanted to be able to read the contents of emails in an inbox. Thats when I went searching in the framework only to find out there there is no support for IMAP in the .NET framework. That's when I found Mailkit and its awesome!

Mailkit can query in inbox in all sorts of ways and works really well. That brings me to this blog post as its a mental bookmark for me if I ever need to do this kind of thing in the future.

To use it, there is nuget package you can use to pull down the library and easily include it in your project:

Install-Package MailKit 

Whats the code like? Well, here is an example of reading an inbox using the library:

using (var client = new ImapClient())
{
    client.ServerCertificateValidationCallback = (sndr, cert, chain, errors) => true;

    client.Connect("server", 993, true);
    client.Authenticate("username", "password");

    client.Inbox.Open(FolderAccess.ReadWrite);

    // The Inbox folder is always available on all IMAP servers...
    var inbox = client.Inbox;
    inbox.Open(FolderAccess.ReadOnly);

    Console.WriteLine("Total messages: {0}", inbox.Count);
    Console.WriteLine("Recent messages: {0}", inbox.Recent);

    // let's search for all messages received after 18/07/2017 with "Funny Joke" in the subject...
    var query = SearchQuery.DeliveredAfter(DateTime.Parse("2017-07-18"))
                           .And(SearchQuery.SubjectContains("Funny Joke"));

    foreach (var uid in inbox.Search(query))
    {
        var message = inbox.GetMessage(uid);
        Console.WriteLine("[match] {0}: {1}", uid, message.Subject);
    }

    foreach (var summary in inbox.Fetch(0, 10, MessageSummaryItems.Full | MessageSummaryItems.UniqueId))
    {
        Console.WriteLine("[summary] {0:D2}: {1}", summary.Index, summary.Envelope.Subject);
    }

    client.Disconnect(true);
}

Wow... That was easy! And here is an example of sending an email using the SMTP client in Mailkit:

using (var client = new MailKit.Net.Smtp.SmtpClient())
{
    client.Connect("server"); 
    client.Authenticate("username", "password");

    var messageToSend = new MimeMessage();
    messageToSend.From.Add(new MailboxAddress("Ocean Airdrop", "oceanairdrop@gmail.com"));
    messageToSend.To.Add(new MailboxAddress("Ocean Airdrop", "oceanairdrop@gmail.com"));
    messageToSend.Subject = "How you doin'?";

    messageToSend.Body = new TextPart("plain")
    {
        Text = @"some message goes here!"
    };

    client.Send(messageToSend);
    client.Disconnect(true);
}

Contact Me:  ocean.airdrop@gmail.com

Popular Posts

Recent Posts

Unordered List

Text Widget

Pages