3674: Illegal characters used in file names are being removed when saving them on the device.
This commit is contained in:
parent
e8eae37389
commit
193450cd63
1 changed files with 22 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue