Wednesday, July 2, 2014

Wildflower

It's a writing in "daydream edition". Everything comes up in mind when I get bored with my routines and it's like nothing can be so exiting. There are many ways to escape from the routines. Walking on the beach, feel the wave hit your feet and hear the sound of water is absolutely relaxing. But that's very common and need a long ride or flight to come there. Another place where you can feel so quite and blessed is a prairie or savanna, or, to mention the closest place.. it might be your garden.
I would love to see wildflowers. It reflects freedom, unmanaged but beautiful composition, colorful, fresh and nature, which can help to free your mind, undisturbed but still remember Allah who create all the things in the best ways. Planting wildflowers in the backyard makes "the best place to see" come to your home. When you need to refresh your mind, wildflowers can spread the amazing feeling which lift your spirit and throw all negative mind away. Wildflowers is originally grow in the wild. But a few mixed species can be found in market.

Tuesday, February 17, 2009

Snow fall 2009

Finally snow came to Beijing. It was on yesterday morning, February 17, 2009. It was soft and small pieces came down to earth.


Friday, February 13, 2009

C# Code to Read Email Attachment

I wrote code in C# to read email from POP3 server. In this case I emphasize on how to save attachment for excel and txt file. I found it is not easy to create the code. Last time I have done this with success test, but when I tried again, it failed to work. And below is my revision, any advice is welcome.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net.Sockets;
using System.Net.Security;
using System.Text.RegularExpressions;

{
string response;
int totmessages;
string msg;
TcpClient mailclient;
SslStream NetStrm;
StreamReader sr;
StreamWriter sw;
NetworkStream ns;
string attachment;
string filename;

string[] data;
int startindex;
int index;
int lastindex;
string x;
MemoryStream ms;
FileStream fs;

//connect to POP3 server
try
{
mailclient = new TcpClient(tbPop.Text, Convert.ToInt16(tbPort.Text));
}
catch (SocketException)
{
tbMessage.Text = "Unable to connect to server 1";
return;
}

if (cbSsl.Checked)
{
NetStrm = new SslStream(mailclient.GetStream());
NetStrm.AuthenticateAsClient(tbPop.Text);
sr = new StreamReader(NetStrm);
sw = new StreamWriter(NetStrm);
}
else
{
ns = mailclient.GetStream();
sr = new StreamReader(ns);
sw = new StreamWriter(ns);
}
response = sr.ReadLine(); //Get opening POP3 banner

sw.WriteLine("user " + tbUid.Text); //Send username
sw.Flush();

response = sr.ReadLine();

if (response.Substring(0, 4) == "-ERR")
{
tbMessage.Text = "Unable to log into server 2";
return;
}

sw.WriteLine("pass " + tbPwd.Text); //Send password
sw.Flush();

response = sr.ReadLine();

if (response.Substring(0, 3) == "-ER")
{
tbMessage.Text = "Unable to log into server 3";
return;
}

sw.WriteLine("stat"); //Send stat command to get number of messages
sw.Flush();

response = sr.ReadLine();

//find number of message
string[] nummess = response.Split(' ');
totmessages = Convert.ToInt16(nummess[1]);

//read emails
for (int i = 1; i <= totmessages; i++)
{
msg = null;

sw.WriteLine("top " + i + " 0"); //read header of each message
sw.Flush();
response = sr.ReadLine();

while (true)
{
response = sr.ReadLine();
if (response == ".")
break;
msg = msg + response + "\r\n";
}

//read attachment
attachment = null;
if (Regex.Match(msg, "multipart/mixed").Success)
{
msg = null;
sw.WriteLine("retr " + i.ToString()); //Retrieve entire message
sw.Flush();
response = sr.ReadLine();

while (true)
{
response = sr.ReadLine();
if (response == ".")
break;
msg = msg + response + "\r\n";
}

if (Regex.Match(msg, tbFile.Text).Success)
{

// below will not work for gmail
//sw.WriteLine("dele " + i.ToString()); //mark for deletion
//sw.Flush();

data = msg.Split('\r');

//tbMessage.Text = msg;

startindex = 0;
index = 0;
lastindex = 0;
x = null;
ms = null;
fs = null;

while (true)
{
attachment = null;
while ((!Regex.Match(data[index].Trim(), "filename").Success)&&(index {
index++;
}
if (index == data.Length-1) break;
filename = data[index].Trim().Substring(42).Replace("\"", "");

//find start of attachment data
index++;
while ((data[index].Length!=1)&&(index {
index++;
}
if (index == data.Length-1) break;
startindex = index + 1;

//find end of data
index = startindex+1;
while ((!Regex.Match(data[index].Trim(), "--0").Success) && (data[index].Length != 1) && (index < data.Length - 1))
{
index++;
}
if (index == data.Length-1) break;
lastindex = index - 1;

for (int j = startindex; j <= lastindex; j++)
{
attachment = attachment + data[j];
}
attachment = attachment + "\r\n";

//saving attachment if xls or txt
if (Regex.Match(filename.ToLower(), "xls").Success)
{
ms = new MemoryStream(Convert.FromBase64String(attachment));
fs = File.OpenWrite("D:\\" + filename);
fs.Write(ms.ToArray(), 0, ms.ToArray().Length);
fs.Close();
}
else if (Regex.Match(filename.ToLower(), "txt").Success)
{
ms = new MemoryStream(Encoding.UTF8.GetBytes(attachment));
fs = File.OpenWrite("D:\\" + filename);
fs.Write(ms.ToArray(), 0, ms.ToArray().Length);
fs.Close();
}

}
}
}
}

sw.WriteLine("quit"); //quit
sw.Flush();

}

Wednesday, January 28, 2009

Chinese New Year and Spring Festival

Malem tahun baru, aku n temen2 mencoba menjadi firework hunter dan memilih lokasi di Wangfujing. Ternyata di sana sepi dan belum banyak kembang api yang dinyalakan. Tambah lagi, camera belom diexplore untuk mode malam. Alhasil foto jepretannya kurang ok. Dua hari setelah new year, kami pergi lagi melihat Temple fair. Temple fair diadakan dalam rangka Spring Festival selama seminggu sejak sehari sebelum tahun baru. Ada beberapa lokasi temple fair, diantaranya di Temple of Earth. Jangan membayangkan ada traditional ceremony dengan national costume, karena yang kami temukan disana hanya permainan2 seperti di amusement park dan pertunjukan musik tari. Tapi oke jg, just to know how it is.
























Ice Festival di Longqing Gorge

Ice and snow festival biasa diadakan kala winter. Berhubung di Beijing ngga turun salju, jalan2 ke ice festival asyik jg. Tempatnya di Barat Laut Beijing, sekitar 1 jam-an dari Beijing, melewati Great Wall. Disana asli dingin n ada ice yg dipahat menjadi sculpture. Nice...




















Finally

Ahh finally, i miss you my blog. Ujian n tugas2 sudah berlalu.. eits, msh ada 1 lagi dink, setelah liburan nanti. Ada beberapa event yg belom diposting disini.. jadi campur aja deh.. berurutan foto-foto Beijing Zoo, Forbidden City, Forbidden City lagi, Tiananmen, Tiananmen lagi n terakhir Beijing Zoo lagi.

















Saturday, November 1, 2008

Koleksi Foto Great Wall

Two weeks ago I went to Great Wall with some friends, mostly international students. There are several gates if you want to enter the Great Wall, all are far apart. One of them is Mutianyu Great Wall. It is located in Huairou District of Beijing. According to history record, this part of Great Wall was built up by General Xuda who serve Emperor Zhu Yuanzhang in early Ming Dynasty. I shot some pictures there, and here are some of them :