StringBuffer sb = new StringBuffer("");
while (s.hasNextLine())
sb.append(s.nextLine() + "\n");
if (!validEmail(sb.toString()))
throw new ParserException(
"Email not a IASI data processed notification email");
Pattern cdPattern = Pattern.compile("\\s*cd\\s{1,}.{1,}?(?:\\s|$)");
Matcher cdMatcher = cdPattern.matcher(sb);
Pattern getPattern = Pattern.compile("\\s*get\\s{1,}.{1,}?(?:\\s|$)");
Matcher getMatcher = getPattern.matcher(sb);
VirtualFile vf = null;
while (cdMatcher.find() && getMatcher.find()) {
String cdCommand = sb.substring(cdMatcher.start(), cdMatcher.end());
String directory = cdCommand.trim().split(" ")[1];
vf = new VirtualFile(root, directory, true);
vf.setNoDirs(true);
String getCommand = sb.substring(getMatcher.start(), getMatcher.end());
String file = getCommand.trim().split(" ")[1];
if (file.endsWith("*")) {
vf.addChild(new VirtualFile(file.substring(0,
file.length() - 1), false));
vf.addChild(new VirtualFile(file.substring(0,
file.length() - 1)
+ ".sig", false));
} else {
vf.addChild(new VirtualFile(file, false));
}
}
Pattern ftpPattern = Pattern.compile("\\sftp\\..*?\\s");
Matcher ftpMatcher = ftpPattern.matcher(sb);
RemoteSite remoteSite = null;
if (ftpMatcher.find()) {
String ftpSite = sb.substring(ftpMatcher.start(), ftpMatcher.end()).trim();
remoteSite = new RemoteSite(null, new URL("ftp://"
+ ftpSite), "anonymous", System
.getenv("user.name")
+ "@jpl.nasa.gov");
}
return new VirtualFileStructure(remoteSite, "/", root);
} catch (Exception e) {
e.printStackTrace();
throw new ParserException("Failed to parse IASI email : "
+ e.getMessage());
}
}