mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-15 22:15:15 -05:00
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
@ -53,6 +53,13 @@ public class AttachmentView extends FrameLayout {
|
|||||||
public long size;
|
public long size;
|
||||||
public ImageView iconView;
|
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;
|
private AttachmentFileDownloadCallback callback;
|
||||||
|
|
||||||
public AttachmentView(Context context, AttributeSet attrs, int defStyle) {
|
public AttachmentView(Context context, AttributeSet attrs, int defStyle) {
|
||||||
@ -196,7 +203,8 @@ public class AttachmentView extends FrameLayout {
|
|||||||
*/
|
*/
|
||||||
public void writeFile(File directory) {
|
public void writeFile(File directory) {
|
||||||
try {
|
try {
|
||||||
File file = Utility.createUniqueFile(directory, name);
|
String filename = removeSpecialCharacters(name);
|
||||||
|
File file = Utility.createUniqueFile(directory, filename);
|
||||||
Uri uri = AttachmentProvider.getAttachmentUri(mAccount, part.getAttachmentId());
|
Uri uri = AttachmentProvider.getAttachmentUri(mAccount, part.getAttachmentId());
|
||||||
InputStream in = mContext.getContentResolver().openInputStream(uri);
|
InputStream in = mContext.getContentResolver().openInputStream(uri);
|
||||||
OutputStream out = new FileOutputStream(file);
|
OutputStream out = new FileOutputStream(file);
|
||||||
@ -204,12 +212,24 @@ public class AttachmentView extends FrameLayout {
|
|||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
in.close();
|
in.close();
|
||||||
attachmentSaved(file.toString());
|
attachmentSaved(filename.toString());
|
||||||
new MediaScannerNotifier(mContext, file);
|
new MediaScannerNotifier(mContext, file);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
attachmentNotSaved();
|
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
|
* saves the file to the defaultpath setting in the config, or if the config
|
||||||
* is not set => to the Environment
|
* is not set => to the Environment
|
||||||
|
Loading…
Reference in New Issue
Block a user