use of i2p.susi.util.FixCRLFOutputStream in project i2p.i2p by i2p.
the class PersistentMailCache method importMail.
/**
* For debugging. Import .eml files from the import/ directory
* @since 0.9.34
*/
private void importMail() {
File importDir = new File(_cacheDir.getParentFile(), DIR_IMPORT);
if (importDir.exists() && importDir.isDirectory()) {
File[] files = importDir.listFiles(new FileSuffixFilter(".eml"));
if (files == null)
return;
for (int i = 0; i < files.length; i++) {
File f = files[i];
// Read in the headers to get the X-UIDL that Thunderbird stuck in there
String uidl = Long.toString(_context.random().nextLong());
InputStream in = null;
try {
in = new FileInputStream(f);
for (int j = 0; j < 20; j++) {
String line = DataHelper.readLine(in);
if (line.length() < 2)
break;
if (line.startsWith("X-UIDL:")) {
uidl = line.substring(7).trim();
break;
}
}
} catch (IOException ioe) {
Debug.debug(Debug.ERROR, "Import failed " + f, ioe);
continue;
} finally {
if (in != null)
try {
in.close();
} catch (IOException ioe) {
}
}
if (uidl == null)
uidl = Long.toString(_context.random().nextLong());
File to = getFullFile(uidl);
if (to.exists()) {
Debug.debug(Debug.DEBUG, "Already have " + f + " as UIDL " + uidl);
f.delete();
continue;
}
in = null;
OutputStream out = null;
try {
in = new FileInputStream(f);
GzipFileBuffer gb = new GzipFileBuffer(to);
// Thunderbird exports aren't CRLF terminated
out = new FixCRLFOutputStream(gb.getOutputStream());
DataHelper.copy(in, out);
} catch (IOException ioe) {
Debug.debug(Debug.ERROR, "Import failed " + f, ioe);
continue;
} finally {
if (in != null)
try {
in.close();
} catch (IOException ioe) {
}
if (out != null)
try {
out.close();
} catch (IOException ioe) {
}
}
f.delete();
Debug.debug(Debug.DEBUG, "Imported " + f + " as UIDL " + uidl);
}
}
}
Aggregations