ContactCSV.toCSV(iterator, sb);
try { iterator = getMailItems(context, item, -1, -1); ContactCSV.toCSV(iterator, sb); } finally { if (iterator instanceof QueryResultIterator) ((QueryResultIterator) iterator).finished(); }
    public void format(Context context, MailItem mailItem) throws IOException, ServiceException {        Iterator iterator = getMailItems(context, mailItem, -1, -1);                StringBuffer sb = new StringBuffer();        ContactCSV.toCSV(iterator, sb);        // todo: get from folder name        String filename = context.itemPath;        if (filename == null || filename.length() == 0)            filename = "contacts";        String cd = Part.ATTACHMENT + "; filename=" + HttpUtil.encodeFilename(context.req, filename + ".csv");        context.resp.addHeader("Content-Disposition", cd);        context.resp.setCharacterEncoding(Mime.P_CHARSET_UTF8);        context.resp.setContentType("text/csv");        context.resp.getOutputStream().print(sb.toString());    }