subject = removeQuote(subject); subject = unMime(subject); from = removeQuote(from);
subject = unMime(removeQuote(subject)); from = unMime(removeQuote(from));
	public static void updateIndex(String whichBox) {		long skipnum = 0;		long skipped = 0;		String subject = null;		String from = null;		String date = null;		String status = null;		String temp = null;		int sep = whichBox.lastIndexOf(File.separator);		String target = whichBox.substring(0, sep + 1) + "." + whichBox.substring(sep + 1, whichBox.length()) + ".index";		BufferedReader in = null;		PrintWriter out = null;		try {			in = new BufferedReader(new InputStreamReader(new FileInputStream(whichBox)));			out   = new PrintWriter(new BufferedOutputStream(new FileOutputStream(target)));			int i = 0;			int unread = 0;			if (hasMail(whichBox)) {				MessageHeaderParser mhp = new MessageHeaderParser();				DateParser dp = new DateParser();				dp.setTargetFormat(YAMM.getString("shortdate"));				try {					skipnum = mhp.parse(in);				} catch (MessageParseException mpe) {					new ExceptionDialog(YAMM.getString("msg.error"), mpe, YAMM.exceptionNames);				}				subject = mhp.getHeaderField("Subject");				from    = mhp.getHeaderField("From");				date    = mhp.getHeaderField("Date");				status  = mhp.getHeaderField("YAMM-Status");				if (status == null) {					status = "Unread";					unread++;				}				if (from == null) from = "";				if (subject == null) subject = "";				subject = removeQuote(subject);				subject = unMime(subject);				from = removeQuote(from);				for (;;) {					temp = in.readLine();					if (temp == null) break;					skipnum += temp.length() + System.getProperty("line.separator").length();					if (temp.equals(".")) {						out.print(i + " ");						if (subject != null) {							out.print("\"" + subject + "\" ");						} else {							out.print("\"\" ");						}						if (from != null) {							out.print("\"" + from + "\" ");						} else {							out.print("\"\" ");						}						if (date != null) {							try {								date = dp.parse(date);							} catch (ParseException pe) {								date = mhp.								getHeaderField("Date");							}							out.print("\"" +date + "\" ");						} else {							out.print("\"\" ");						}						out.print("\"" + status + "\" ");						out.println(skipped);						out.flush();						i++;						skipped = skipnum;						try {							skipnum += mhp.parse(in);						} catch (MessageParseException mpe) {							break;						}						subject = mhp.getHeaderField("Subject");						from    = mhp.getHeaderField("From");						date    = mhp.getHeaderField("Date");						status  = mhp.getHeaderField("YAMM-Status");						if (status == null) {							status = "Unread";							unread++;						}						if (from == null)							from = "";						if (subject == null)							subject = "";						subject = removeQuote(subject);						subject = unMime(subject);						from = removeQuote(from);					}				}				in.close();				out.close();				in = new BufferedReader(new InputStreamReader(							new FileInputStream(target)));				out = new PrintWriter(new BufferedOutputStream(							new FileOutputStream(target + ".tmp")));				out.println(i + ", " + unread);				for (;;) {					String tmp = in.readLine();					if (tmp == null) break;					else out.println(tmp);				}				in.close();				out.close();				File tmp = new File(target + ".tmp");				File old = new File(target);				old.delete();				tmp.renameTo(old);			} else {				out.println("0, 0");			}		} catch(IOException ioe) {			new ExceptionDialog(YAMM.getString("msg.error"), ioe, YAMM.exceptionNames);		} finally {			try {				if (in != null) in.close();				if (out != null) out.close();			} catch (IOException ioe) {}		}	}