Yosemite Mail app: Can’t send Gmail messages

Recently, I decided to download all my mail into Mail app. I wanted to be able to receive and send using my existing Gmail account, but it didn’t work for me. I kept getting a prompt that Gmail was offline, when I knew otherwise. (Sending via mail.google.com web app worked, for example.)

After some digging, I found the solution in an Apple discussion forum. In case the answer ever gets buried (I hope not), it is related to truncation of the SMTP username; e.g. “kzhiwei@gmail.com” is shortened to “kzhiwei”. This does not work. To change, load up Mail, then click into Preferences > Accounts > Outgoing Mail Server (SMTP) > Edit SMTP Server List. Switch to the Advanced tab, then change the “User Name” field. For your reference, mine looks like:

Screenshot 2015-03-09 14.02.46

As usual, your mileage may vary. (And you’ll need to enable IMAP for Gmail, too.)

Android: FBreader screen grabs

I’ve bee doing quite a bit of reading nowadays. Every now and then I happen upon good writing. These resonate with me, so instead of taking a screen capture, I’m re-posting here instead where someone, someday might perhaps admire (and go read the book). This is a sticky post, so it’ll be updated as I slowly move these into text…

The Cuckoo’s Calling (Robert Galbraith): A lie would have no sense unless the truth were felt as dangerous.

The Elfstones of Shannara (Terry Brooks): Give thought to the purpose for those questions. Give thought to their source. Hurt gives way to bitterness, bitterness to anger. Travel too far that road, and the way is lost.

The Elves of Cintra (Terry Brooks): Her presence comforted him as nobody else could, and he was grateful for her beyond anything worlds could express.

Ender’s Game (Orson Scott Card): The story of Ender’s Game is not this book though it has that title emblazoned on it. The story is one that you and I will construct together in your memory. If the story means anything to you at all, then when you. remember it afterward, think of it, not as something I created, but rather as something that we made together.

Ender’s Game (Orson Scott Card): I didn’t want to see you. They told me. I was afraid I’d still love you. I hoped that you would. My fear, your wish — both granted.

Ender’s Game (Orson Scott Card): I am not a happy man, Ender. Humanity does not ask us to be happy. It merely asks us to be brilliant on its behalf. Survival first, then happiness as we can manage it.

The First King of Shannara (Terry Brooks): Time stole away commitments and loosened ties. Friendship were reduced to tales of the past and vague promises for the future, neither strong enough to recover what was lost. But that was what life did – it took you down separate roads until one day you found yourself alone.

The First King of Shannara (Terry Brooks): That’s how it is with parents and children. Each disappoints the other n ways that neither recognizes nor intends, and it takes time to overcome that disappointment.

The First King of Shannara (Terry Brooks): But it marked you. For a time, but not in any lasting way. Perhaps it even helped toughen me. I don’t pretend to know. We grow as best we can under the circumstances given us. What good does it do to second-guess ourselves years after the fact? Better that we simply try to understand why we are as we are and then better ourselves by learning from that.

The Gypsy Morph (Terry Brooks): He says nothing in response, but words are not necessary when she feels the gentle squeeze of his hand over hers. He understands. He is happy, too. They walk for a long time, content just to be with each other, like father and daughter, like family. She thinks of them this way, of herself as his daughter, him as her father. There is more to family than shared blood. There is trust and friendship and commitment. She is only eight years old, but she already knows this.

A Knight of the Word (Terry Brooks): I was just in the neighborhood, and decided to stop by, share a few laughs, maybe see if you’re in the market for a boyfriend.

A Knight of the Word (Terry Brooks): The horror of what had happened enveloped and consumed him. It haunted his sleep and destroyed his peace of mind. He could not function. He sat paralyzed in small rooms far away from San Sobel, trying to regain his sense of purpose. He had experienced failure before, but nothing with consequences that were so dramatic and so personal. He had thought he could handle anything, but he wasn’t prepared for this.

A Knight of the Word (Terry Brooks): He cried often, and he ached deep inside. He replayed the events over and over in his head, trying to decide what it was he had done wrong.

A Knight of the Word (Terry Brooks): We are homeless in the streets and we are homeless in our hearts as well. We have no purpose in the world. We have no center. Our way of life was changed for us long ago, and it will never return.

A Knight of the Word (Terry Brooks): We are a people under siege, walled away from each other and the world, trying to fend a safe path through the debris of hate and rage that collects around us. We drive our cars as if they were weapons. We use our children and friends as if their love and trust were expendable and meaningless. We think of ourselves first and others second. We lie and cheat and steal in little ways, thinking it unimportant, justifying it by telling ourselves that others do it, too. We have no patience with the mistake of others. We have no empathy for their despair. We have no compassion for their misery.

A Knight of the Word (Terry Brooks): What we have in life we can count our own is who we are, and where we come from, she thought absently.

The Ocean at the End of the Lane (Neil Gaiman): An admission about myself: as a very small boy, perhaps three or four years old, I could be a monster. “You were a momzer,” several aunts told me, on different occasions, once I had safely reached adulthood and my dreadful infant deeds could be recalled with wry amusement. But I don’t actually remember being a monster. I just remember wanting my own way.

Running with the Demon (Terry Brooks): Doubts set in. Had he dreamed it all? Had he imagined her? Or worse, had he mistaken her intent? What if the great purpose he had envisioned, the purpose for which he had searched so long, was a lie? Doubts turned to mistrust. What if he had been deceived? He was beset by nightmares that woke him shaking and chilly on the hottest nights, sweaty and fiery on the coldest nights.

Ten Pieces of Inspiration #158 (Trent Hamm): Some of the biggest mistakes in my life have come from giving up on relationships because they happened to not be easy at the moment.

Proftpd for CentOS 6

More of a note to self than anything. As usual, YMMV.

1. Add RPMForge repo.

# rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el5.rf.x86_64.rpm
# rpm -Uvh rpmforge-release-0.5.3-1.el5.rf.x86_64.rpm
# yum install proftpd -y
# chkconfig --level 345 proftpd on
# /etc/init.d/proftpd restart
# netstat -tnlp|grep proftpd
tcp 0 0 :::21 :::* LISTEN 36615/proftpd

2. Configure iptables.

# iptables -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
# etc/init.d/iptables save; etc/init.d/iptables restart

3. New Linux user.

# useradd foo -p /path/to/home/directory
# passwd foo

4a. Failed login #1; e.g.

Command: USER foo
Response: 331 Password required for foo
Command: PASS ********
Response: 530 Login incorrect.
Error: Critical error: Could not connect to server

4b. Note /var/log/secure erros; e.g.

Oct 29 03:41:07 bar proftpd: PAM unable to dlopen(/lib64/security/pam_stack.so): /lib64/security/pam_stack.so: cannot open shared object file: No such file or directory
Oct 29 03:41:07 bar proftpd: PAM adding faulty module: /lib64/security/pam_stack.so
Oct 29 03:41:07 bar proftpd[36319]: 127.0.0.1 (192.168.128.29[192.168.128.29]) - USER foo (Login failed): Incorrect password.

4c. Fix PAM config for proftpd-1.3.4a-1.el6.rf.x86_64.

# cat /etc/pam.d/proftpd
#%PAM-1.0M-1.0
auth required pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed
auth required pam_shells.so
auth include system-auth
account include system-auth
session include system-auth
session required pam_loginuid.so
# /etc/init.d/proftpd restart

4d. Failed login #2; e.g.

Command: PWD
Response: 257 "/" is the current directory
Command: TYPE I
Response: 200 Type set to I
Command: PASV
Response: 227 Entering Passive Mode.
Command: MLSD
Error: Connection timed out
Error: Failed to retrieve directory listing

4e. Configure passive FTP.

# iptables -A INPUT -p tcp -m multiport --dports 60000:65535 -j ACCEPT
# etc/init.d/iptables save; etc/init.d/iptables restart
# cat /etc/proftpd.conf|grep PassivePort
PassivePorts 60000 65535
# /etc/init.d/proftpd restart

5. Success!

Command: MLSD
Response: 150 Opening ASCII mode data connection for MLSD
Response: 226 Transfer complete
Status: Directory listing successful

References

http://www.linfo.org/useradd.html
http://pkgs.org/centos-6/repoforge-x86_64/proftpd-1.3.4a-1.el6.rf.x86_64.rpm.html
http://www.proftpd.org/docs/howto/NAT.html
http://blog.redbranch.net/2012/04/17/proftpd-centos-6-pam-unable-to-dlopen-lib64securitypam_stack-so/
http://serverfault.com/questions/594835/what-is-the-correct-way-to-open-a-range-of-ports-in-iptables

CentOS: httpd invalid command

Was configuring a CentOS 6 server recently, and I decided to comment out all httpd (i.e. Apache) LoadModule directives. Upon restart, there were several invalid commands, so I took the time to note ’em down as it wasn’t obvious (to me, at least) which commands were provided by which modules.

I liken this to a cheat sheet to http://httpd.apache.org/docs/2.2/ then:


Invalid command 'AddHandler': mod_mime
Invalid command 'Alias': mod_alias
Invalid command 'BrowserMatch': mod_setenvif
Invalid command 'DirectoryIndex': mod_dir
Invalid command 'IndexOptions': mod_autoindex
Invalid command 'LanguagePriority': mod_negotiation
Invalid command 'LogFormat': mod_log_config
Invalid command 'Order': mod_authz_host
Invalid command 'TransferLog': mod_log_config

OS X: Icon^M file

When I use Terminal, I’ve noticed that the OS creates this Icon^M for folders that I created. It’s quite irritating (I’m not sure what it’s for), and Eclipse was choking on it last semester. I never figured out why until today. So apparently it is a custom icon (but I didn’t set one!), so I can delete ’em via Terminal; e.g.

woteba:~ kzhiwei$ find . -name Icon*
./Icon
woteba:~ kzhiwei$ find . -name Icon* | xargs rm -rf

More reading: http://superuser.com/questions/298785/icon-file-on-os-x-desktop

Android: restoring app data via adb push

So after taking CI6230 I decided to encrypt my phone storage. I was running CyanogenMod (CM) 10.1.2, which is awesome. But I digress. So the encryption went fine. It took awhile, and things were A-OK until I decided to tinker with my phone — despite all of the horror stories and downtime I’ve endured (my colleagues can attest to that) and try Paranoid Android (PA) 3.94. I mean, we’re explorers aren’t we?

So I downloaded the ROM and Google Apps zip files after doing Titanium Backup (of course!) and copied everything to my Mac (in hindsight, this was what saved me, even though I didn’t realize it at that time), and then rebooted to recovery.

In recovery, I realized the storage couldn’t be accessed as it was encrypted. I seem to recall unrooting (and rooting) the phone, and then it wouldn’t even boot into the ROM. OK, so I’d rendered my phone unworkable (again). I was stumped for awhile, but luckily Google provides Nexus factory images and the Android SDK so I used that to reset things. Now I had a working device, but I was unhappy because my app data was now lost. All the save games… and then some.

So I figured that I could just flash PA and then restore using TitaniumBackup, as I’d always done before. The problem was, it didn’t work. I got a parse error message. I decided to ignore the error, and reinstalled via Google Play, following by a data-only restore; i.e. just the .properties and .tar.gz files. Now this caused the applications to crash, leading me to think that my files were encrypted. I was sidetracked by the fact that the applications crashed repeatedly, and Liya could only display the Liya the table structure, but there was no data.

So I pretty much did a ton of research trying to find out what happened:

https://santoku-linux.com/howto/mobile-forensics/how-to-brute-force-android-encryption
https://www1.informatik.uni-erlangen.de/frost

I even used openssl to attempt decrypt, since I remembered my pin, and I knew the cipher; e.g.

$ openssl aes-128-cbc -d -in financisto.db -nosalt -out financisto.db.clear

I am ashamed to note that I’m a noob. Vim gave me a hint, in that the DML was not enciphered. I could see something like ‘create table foo…’, but I ignored it. Then I realized then AES 128 ciphertext didn’t even look like what I had, and then I opened it using the sqlite3 tool:

$ sqlite3 financisto.db
SQLite version 3.7.7 2011-06-25 16:35:41
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from transactions;
1|1|0|0|0|0|Opening amount (MYR)|53400|0|1300572979084||0.0|0.0|0.0||0||||UR||0|1300572979086|0|0|0|0
.
.
.

OK, nothing was encrypted after all, but my apps wouldn’t work. The trick was to use adb push to individually push files into the device. It’s pretty tedious, but in the end it worked for me. Just tar -xof the .tar.gz, and then descend into data/data for the list of files to push over:

$ FOO=/data/data/ru.orangesoftware.financisto/databases/
$ BAR=financisto.db
$ adb push ~/Dropbox/Mako/TitaniumBackup/$FOO/$BAR $FOO

Setting the envvars will help things move along a lot faster, then after that you should have app+data.

Hope this helps some poor paranoid soul like myself sometime soon. Of course, your mileage will vary.

Android: XML layouts

So, I’ve been fiddling around w/ ADT for a couple of hours now. It’s possible to programmatically create layouts (i.e. an Android UI), but it’s not a great solution. It’s way easier to define the layout in XML, and then bind whatever event handlers are required. Here we have a simple class:

package com.waynekhan;

import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.widget.*;
import java.util.*;


public class HWA extends Activity implements View.OnClickListener {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);
Button b = (Button) findViewById(R.id.b);
b.setOnClickListener(this);
}

public void onClick(View v) {
switch (v.getId()) {
case R.id.b: {
Button b = (Button) v;
b.setText(new Date().toString()); break;
}
}
}
}

As you can see, it’s quite bare. Load an XML layout (R.layout.main), define a button (R.id.b) and then bind a click listener to said button. Then we have onClick() which simply sets the button text to the current String-ified date. Our code is really clean, and we do all the UI-related stuff in /res/layout/main.xml, and put all our conveniently l10n strings in /res/values/strings.xml. Unfortunately, I can’t post the content of the XML files, since WordPress groks ’em and all I get is an empty code block.

Follow

Get every new post delivered to your Inbox.