Attachment a = new Attachment(); a.parse(in, boundary, baseFile);
final BufferedReader i = in; final String b = boundary; final String bf = baseFile; Thread t = new Thread() { public void run() { try { Attachment a = new Attachment(); a.parse(i, b, bf); } catch (Exception e) { } } }; t.setPriority(Thread.MIN_PRIORITY); t.start();
	public void parse(BufferedReader in, String boundary, String baseFile)		throws IOException, MessageParseException	{		MessageHeaderParser mhp = new MessageHeaderParser();		mhp.parse(in);		String encoding = null;  // Encoding used for this attachment		String fileName = null; // the file we write the data to		if (mhp.getHeaderField("Content-Type") != null) {			contentType = name = mhp.getHeaderField("Content-Type").trim();			if (name.toLowerCase().indexOf("name=") != -1) {				// remove unwanted info				name = name.substring(name.toLowerCase().indexOf("name=") + 5, name.length()).trim();				if (name.indexOf(";") != -1) {					name = name.substring(0, name.indexOf(";")).trim();				}				if (name.startsWith("\"") && name.endsWith("\"")) {					name = name.substring(1, name.length() - 1);				}			} else {				name = null;			}		}		if (mhp.getHeaderField("Content-Disposition") != null) {			contentDisposition = mhp.getHeaderField("Content-Disposition");			if (name == null) {				name = contentDisposition;				if (name.toLowerCase().indexOf("filename=") != -1) {					name = name.substring(name.toLowerCase().indexOf("filename=") + 9, name.length()).trim();					if (name.indexOf(";") != -1) {						name = name.substring(0, name.indexOf(";"));					}					if (name.startsWith("\"") && name.endsWith("\"")) {						name = name.substring(1, name.length() - 1);					}				} else {					name = null;				}			}		}		if (name != null) name = Mailbox.unMime(name);		if (mhp.getHeaderField("Content-Transfer-Encoding") != null) {			encoding = mhp.getHeaderField("Content-Transfer-Encoding").trim();		}		if (contentType.indexOf("multipart/alternative") != -1) {			String temp = contentType.toLowerCase();			if (temp.indexOf("boundary=") != -1) {				temp = contentType.substring(temp.indexOf("boundary=") + 9, contentType.length());				if (temp.startsWith("\"")) {					temp = temp.substring(1, temp.length() - 1);				}				if (boundary.indexOf("\"") != -1) {					temp = temp.substring(0, temp.indexOf("\""));				}			}			Attachment a = new Attachment();			a.parse(in, temp, baseFile);			while ((temp = in.readLine()) != null) {				if (temp.startsWith("--" + boundary)) {					if (!temp.endsWith("--")) {						a = new Attachment();						a.parse(in, boundary, baseFile);						break;					} else {						break;					}				}			}			return;		}		PrintWriter out = null;		try {			String temp = null;			fileName = baseFile;			boolean html = false;			if (contentDisposition != null) 				fileName = baseFile + ".attach." + name;			else if (contentType.indexOf("text/html") != -1) {				fileName = baseFile + ".message.html";				html = true;			} else if (contentType.indexOf("text/plain") != -1)				fileName = baseFile + ".message.txt";			else if (name != null) {				fileName = baseFile + ".attach." + name;			} else {				System.err.println(contentDisposition);				System.err.println(contentType);				throw new MessageParseException("Unknown type of attachment!");			}			out = new PrintWriter(				new BufferedOutputStream(					new FileOutputStream(fileName)				)			);			while ((temp = in.readLine()) != null) {				if (temp.startsWith("--" + boundary)) {					if (!temp.endsWith("--")) {						Attachment a = new Attachment();						a.parse(in, boundary, baseFile);						break;					} else {						break;					}				} else {					out.println(temp);					out.flush();				}			}		} finally {			if (out != null) {				out.close();			}		}		if (fileName.indexOf(".message.") != -1) {			MessageParser.filter(contentType, encoding, fileName);		} else {			// attachments are not needed to display the message			// so we can filter them in a thread			final String c = contentType;			final String e = encoding;			final String f = fileName;			Thread t = new Thread()			{				public void run() {					try {						MessageParser.filter(c, e, f);					} catch (IOException ioe) {						new ExceptionDialog(							YAMM.getString("msg.error"),							ioe,							YAMM.exceptionNames						);					}				}			};			t.setPriority(Thread.MIN_PRIORITY);			t.start();		}	}