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