1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-24 08:38:51 -05:00

3674: Illegal characters used in file names are being removed when saving them on the device.

This commit is contained in:
wilian-cb 2012-01-26 19:25:46 -02:00 committed by cketti
parent e8eae37389
commit 193450cd63

View File

@ -52,6 +52,13 @@ public class AttachmentView extends FrameLayout {
public String contentType;
public long size;
public ImageView iconView;
/**
* Regular expression that represents characters that aren't allowed
* to be used in file names saved using K-9
*/
private static final String specialCharacters = new String("[^\\d\\s\\w!" +
"#\\$%&'\\(\\)\\-@\\^_`\\{\\}~.,]");
private AttachmentFileDownloadCallback callback;
@ -196,7 +203,8 @@ public class AttachmentView extends FrameLayout {
*/
public void writeFile(File directory) {
try {
File file = Utility.createUniqueFile(directory, name);
String filename = removeSpecialCharacters(name);
File file = Utility.createUniqueFile(directory, filename);
Uri uri = AttachmentProvider.getAttachmentUri(mAccount, part.getAttachmentId());
InputStream in = mContext.getContentResolver().openInputStream(uri);
OutputStream out = new FileOutputStream(file);
@ -204,12 +212,24 @@ public class AttachmentView extends FrameLayout {
out.flush();
out.close();
in.close();
attachmentSaved(file.toString());
attachmentSaved(filename.toString());
new MediaScannerNotifier(mContext, file);
} catch (IOException ioe) {
attachmentNotSaved();
}
}
/**
* Removes characters that aren't allowed to be used in file names saved
* in K-9 application.
*
* @param filename The original file name.
* @return A file name with only legal characters.
*/
private String removeSpecialCharacters(String filename) {
return filename.replaceAll(specialCharacters, "");
}
/**
* saves the file to the defaultpath setting in the config, or if the config
* is not set => to the Environment