refactor mailThread.js
try to avoid Maximum call stack size exceeded error