// check if a FileDataSource for this name has already been attached;
// if so, return the cached CID value.
if (inlineEmbeds.containsKey(file.getName()))
{
InlineImage ii = (InlineImage) inlineEmbeds.get(file.getName());
FileDataSource fileDataSource = (FileDataSource) ii.getDataSource();
// make sure the supplied file has the same canonical path
// as the one already associated with this name.
String existingFilePath = null;
try
{
existingFilePath = fileDataSource.getFile().getCanonicalPath();
}
catch (IOException ioe)
{
throw new EmailException("couldn't get canonical path for file "
+ fileDataSource.getFile().getName()
+ "which has already been embedded", ioe);
}
if (filePath.equals(existingFilePath))
{
return ii.getCid();
}
else
{
throw new EmailException("embedded name '" + file.getName()
+ "' is already bound to file " + existingFilePath
+ "; existing names cannot be rebound");
}
}
// verify that the file is valid
if (!file.exists())
{
throw new EmailException("file " + filePath + " doesn't exist");
}
if (!file.isFile())
{
throw new EmailException("file " + filePath + " isn't a normal file");
}
if (!file.canRead())
{
throw new EmailException("file " + filePath + " isn't readable");
}
return embed(new FileDataSource(file), file.getName());
}