Back out Attachments-on-SD support (it's on a feature branch now, while

Bao-Long makes it extra-awesome)

This commit should revert:
r1445
r1437
r1436
r1449
r1442
r1441
r1419
r1414
r1413
This commit is contained in:
Jesse Vincent 2010-02-18 03:28:31 +00:00
parent c5851f2866
commit f9d39e4814
10 changed files with 97 additions and 407 deletions

View File

@ -670,11 +670,4 @@ Welcome to K-9 Mail setup. K-9 is an open source mail client for Android origin
<string name="remote_control_label">K-9 Mail remote control</string>
<string name="remote_control_desc">Allows this application to control K-9 Mail activities and settings.</string>
<string name="account_setup_store_attachment_on_sd_card_label">Attachments on SD card</string>
<string name="account_setup_store_attachment_on_sd_card_summary">Whether or not attachments are stored on the SD card</string>
<string name="account_setup_store_attachment_on_sd_card_error">No SD card found</string>
<string name="sd_card_error">No SD card found</string>
<string name="sd_card_skip">No SD card found. Skipping accounts with 'Attachments on SD card' enabled.</string>
</resources>

View File

@ -30,16 +30,9 @@
android:key="account_default"
android:title="@string/account_settings_default_label"
android:summary="@string/account_settings_default_summary" />
<CheckBoxPreference
android:key="account_setup_store_attachment_on_sd_card"
android:title="@string/account_setup_store_attachment_on_sd_card_label"
android:summary="@string/account_setup_store_attachment_on_sd_card_summary" />
</PreferenceCategory>
</PreferenceCategory>
<PreferenceCategory android:title="@string/account_settings_message_lists">
<PreferenceCategory android:title="@string/account_settings_message_lists">
<ListPreference
android:key="account_display_count"

View File

@ -1,11 +1,9 @@
package com.fsck.k9;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.util.Log;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.MessagingException;
@ -298,7 +296,6 @@ public class Account implements Serializable
}
mIsSignatureBeforeQuotedText = preferences.getPreferences().getBoolean(mUuid + ".signatureBeforeQuotedText", false);
mStoreAttachmentsOnSdCard = preferences.getPreferences().getBoolean(mUuid + ".storeAttachmentOnSdCard", false);
identities = loadIdentities(preferences.getPreferences());
}
@ -559,7 +556,6 @@ public class Account implements Serializable
editor.remove(mUuid + ".signatureBeforeQuotedText");
editor.remove(mUuid + ".expungePolicy");
editor.remove(mUuid + ".maxPushFolders");
editor.remove(mUuid + ".storeAttachmentOnSdCard");
deleteIdentities(preferences.getPreferences(), editor);
editor.commit();
}
@ -632,21 +628,9 @@ public class Account implements Serializable
editor.putBoolean(mUuid + ".signatureBeforeQuotedText", this.mIsSignatureBeforeQuotedText);
editor.putString(mUuid + ".expungePolicy", mExpungePolicy);
editor.putInt(mUuid + ".maxPushFolders", mMaxPushFolders);
editor.putBoolean(mUuid + ".storeAttachmentOnSdCard", mStoreAttachmentsOnSdCard);
saveIdentities(preferences.getPreferences(), editor);
editor.commit();
try
{
LocalStore localStore = (LocalStore)Store.getInstance(mLocalStoreUri, K9.app);
localStore.setStoreAttachmentsOnSdCard(mStoreAttachmentsOnSdCard);
}
catch (MessagingException e)
{
//Should not happen
Log.w(K9.LOG_TAG, null, e);
}
}
public String toString()
@ -1029,13 +1013,4 @@ public class Account implements Serializable
mRing = ring;
}
public boolean isStoreAttachmentOnSdCard()
{
return mStoreAttachmentsOnSdCard;
}
public void setStoreAttachmentOnSdCard(boolean mStoreAttachmentOnSdCard)
{
this.mStoreAttachmentsOnSdCard = mStoreAttachmentOnSdCard;
}
}

View File

@ -31,7 +31,6 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.os.PowerManager;
import android.os.Process;
import android.os.PowerManager.WakeLock;
@ -47,6 +46,7 @@ import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.MessageRemovalListener;
import com.fsck.k9.mail.MessageRetrievalListener;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Part;
import com.fsck.k9.mail.PushReceiver;
import com.fsck.k9.mail.Pusher;
@ -54,7 +54,6 @@ import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.Transport;
import com.fsck.k9.mail.Folder.FolderType;
import com.fsck.k9.mail.Folder.OpenMode;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.internet.MimeMessage;
import com.fsck.k9.mail.internet.MimeUtility;
import com.fsck.k9.mail.internet.TextBody;
@ -62,10 +61,6 @@ import com.fsck.k9.mail.store.LocalStore;
import com.fsck.k9.mail.store.LocalStore.LocalFolder;
import com.fsck.k9.mail.store.LocalStore.LocalMessage;
import com.fsck.k9.mail.store.LocalStore.PendingCommand;
import com.fsck.k9.mail.transport.EOLConvertingOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* Starts a long running (application) Thread that will run through commands
@ -3878,19 +3873,13 @@ public class MessagingController implements Runnable
for (final Account account : accounts)
{
if (account.isStoreAttachmentOnSdCard()
&& !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "SD card not mounted: skipping synchronizing account " + account.getDescription());
continue;
}
final long accountInterval = account.getAutomaticCheckIntervalMinutes() * 60 * 1000;
if (ignoreLastCheckedTime == false && accountInterval <= 0)
{
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Skipping synchronizing account " + account.getDescription());
continue;
}
@ -3991,16 +3980,6 @@ public class MessagingController implements Runnable
{
public void run()
{
//Let's be conservative and check the sd card
//in case it was unmounted while we are sync'ing this account
if (account.isStoreAttachmentOnSdCard()
&& !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "SD card not mounted: skipping synchronizing: account " + account.getDescription() + " folder=" + folder.getName());
return;
}
LocalFolder tLocalFolder = null;
try
{
@ -4555,14 +4534,6 @@ public class MessagingController implements Runnable
{
public void run()
{
if (account.isStoreAttachmentOnSdCard()
&& !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "SD card not mounted: skipping reception of pushed messages: account=" + account.getDescription() + ", folder=" + remoteFolder.getName() + ", message count=" + messages.size());
throw new RuntimeException("SD card unavailable/required");
}
LocalFolder localFolder = null;
try
{

View File

@ -9,7 +9,6 @@ import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.view.*;
import android.view.ContextMenu.ContextMenuInfo;
@ -383,29 +382,6 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
*/
private void onCheckMail(Account account)
{
if (account != null)
{
if (account.isStoreAttachmentOnSdCard()
&& !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
Toast.makeText(this, R.string.sd_card_error, Toast.LENGTH_SHORT).show();
return;
}
}
else
{
Account[] accounts = Preferences.getPreferences(this).getAccounts();
for (Account acc : accounts)
{
if (acc.isStoreAttachmentOnSdCard()
&& !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
Toast.makeText(this, R.string.sd_card_skip, Toast.LENGTH_LONG).show();
break;
}
}
}
MessagingController.getInstance(getApplication()).checkMail(this, account, true, true, null);
}

View File

@ -8,7 +8,6 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
@ -173,13 +172,6 @@ public class FolderList extends K9ListActivity
private void checkMail(FolderInfoHolder folder)
{
if (mAccount.isStoreAttachmentOnSdCard()
&& !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
Toast.makeText(this, R.string.sd_card_error, Toast.LENGTH_SHORT).show();
return;
}
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
final WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Email - UpdateWorker");
wakeLock.setReferenceCounted(false);
@ -458,13 +450,6 @@ public class FolderList extends K9ListActivity
private void checkMail(final Account account)
{
if (mAccount.isStoreAttachmentOnSdCard()
&& !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
Toast.makeText(this, R.string.sd_card_error, Toast.LENGTH_SHORT).show();
return;
}
MessagingController.getInstance(getApplication()).checkMail(this, account, true, true, mAdapter.mListener);
}

View File

@ -10,9 +10,11 @@ import android.content.Intent;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.text.SpannableString;
import android.text.Spannable;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.text.style.TextAppearanceSpan;
import android.util.Config;
import android.util.Log;
@ -970,13 +972,6 @@ public class MessageList
private void checkMail(Account account, String folderName)
{
if (mAccount.isStoreAttachmentOnSdCard()
&& !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
Toast.makeText(this, R.string.sd_card_error, Toast.LENGTH_SHORT).show();
return;
}
mController.synchronizeMailbox(account, folderName, mAdapter.mListener);
sendMail(account);
}

View File

@ -5,12 +5,9 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
import android.preference.*;
import android.preference.Preference.OnPreferenceChangeListener;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;
import com.fsck.k9.*;
import com.fsck.k9.Account.FolderMode;
import com.fsck.k9.activity.ChooseFolder;
@ -50,7 +47,6 @@ public class AccountSettings extends K9PreferenceActivity
private static final String PREFERENCE_DELETE_POLICY = "delete_policy";
private static final String PREFERENCE_EXPUNGE_POLICY = "expunge_policy";
private static final String PREFERENCE_AUTO_EXPAND_FOLDER = "account_setup_auto_expand_folder";
private static final String PREFERENCE_STORE_ATTACHMENTS_ON_SD_CARD = "account_setup_store_attachment_on_sd_card";
private Account mAccount;
@ -73,7 +69,6 @@ public class AccountSettings extends K9PreferenceActivity
private ListPreference mDeletePolicy;
private ListPreference mExpungePolicy;
private Preference mAutoExpandFolder;
private CheckBoxPreference mStoreAttachmentsOnSdCard;
private boolean mIncomingChanged = false;
@ -359,28 +354,6 @@ public class AccountSettings extends K9PreferenceActivity
return true;
}
});
mStoreAttachmentsOnSdCard = (CheckBoxPreference) findPreference(PREFERENCE_STORE_ATTACHMENTS_ON_SD_CARD);
mStoreAttachmentsOnSdCard.setChecked(mAccount.isStoreAttachmentOnSdCard());
mStoreAttachmentsOnSdCard.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue instanceof Boolean)
{
Boolean b = (Boolean)newValue;
if (b.booleanValue()
&& !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
Toast.makeText(
AccountSettings.this,
R.string.account_setup_store_attachment_on_sd_card_error,
Toast.LENGTH_SHORT).show();
return false;
}
}
return true;
}
});
}
@Override
@ -406,7 +379,6 @@ public class AccountSettings extends K9PreferenceActivity
mAccount.setFolderTargetMode(Account.FolderMode.valueOf(mTargetMode.getValue()));
mAccount.setDeletePolicy(Integer.parseInt(mDeletePolicy.getValue()));
mAccount.setExpungePolicy(mExpungePolicy.getValue());
mAccount.setStoreAttachmentOnSdCard(mStoreAttachmentsOnSdCard.isChecked());
boolean needsRefresh = mAccount.setAutomaticCheckIntervalMinutes(Integer.parseInt(mCheckFrequency.getValue()));
needsRefresh |= mAccount.setFolderSyncMode(Account.FolderMode.valueOf(mSyncMode.getValue()));

View File

@ -8,10 +8,8 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.os.Environment;
import android.text.util.Regex;
import android.util.Log;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.Preferences;
import com.fsck.k9.Utility;
@ -38,11 +36,9 @@ public class LocalStore extends Store implements Serializable
private static final int DB_VERSION = 33;
private static final Flag[] PERMANENT_FLAGS = { Flag.DELETED, Flag.X_DESTROYED, Flag.SEEN };
private boolean mStoreAttachmentsOnSdCard;
private String mPath;
private SQLiteDatabase mDb;
private File mInternalAttachmentsDir = null;
private File mExternalAttachmentsDir = null;
private File mAttachmentsDir;
private Application mApplication;
private String uUid = null;
@ -69,7 +65,6 @@ public class LocalStore extends Store implements Serializable
public LocalStore(String _uri, Application application) throws MessagingException
{
mApplication = application;
URI uri = null;
try
{
@ -99,31 +94,10 @@ public class LocalStore extends Store implements Serializable
parentDir.mkdirs();
}
mInternalAttachmentsDir = new File(mPath + "_att");
if (!mInternalAttachmentsDir.exists())
mAttachmentsDir = new File(mPath + "_att");
if (!mAttachmentsDir.exists())
{
mInternalAttachmentsDir.mkdirs();
}
String externalAttachmentsPath = "/sdcard" + mPath.substring("//data".length());
mExternalAttachmentsDir = new File(externalAttachmentsPath + "_att");
Account account = null;
for (Account aAccount : Preferences.getPreferences(mApplication).getAccounts())
{
if (_uri.equals(aAccount.getLocalStoreUri()))
{
account = aAccount;
break;
}
}
if (account == null)
{
//Should not happend
throw new IllegalArgumentException("No account found: uri=" + _uri);
}
else
{
this.setStoreAttachmentsOnSdCard(account.isStoreAttachmentOnSdCard());
mAttachmentsDir.mkdirs();
}
mDb = SQLiteDatabase.openOrCreateDatabase(mPath, null);
@ -261,37 +235,18 @@ public class LocalStore extends Store implements Serializable
{
long attachmentLength = 0;
attachmentLength =+ getSize(mInternalAttachmentsDir);
if (isExternalAttachmentsDirReady())
File[] files = mAttachmentsDir.listFiles();
for (File file : files)
{
attachmentLength =+ getSize(mExternalAttachmentsDir);
}
File dbFile = new File(mPath);
return dbFile.length() + attachmentLength;
}
private long getSize(File attachmentsDir)
{
long attachmentLength = 0;
File[] files = attachmentsDir.listFiles();
if (files==null)
{
Log.w(K9.LOG_TAG, "Unable to list files: " + attachmentsDir.getAbsolutePath());
}
else
{
for (File file : files)
if (file.exists())
{
if (file.exists())
{
attachmentLength += file.length();
}
attachmentLength += file.length();
}
}
return attachmentLength;
File dbFile = new File(mPath);
return dbFile.length() + attachmentLength;
}
public void compact() throws MessagingException
@ -420,13 +375,24 @@ public class LocalStore extends Store implements Serializable
{
}
delete(mInternalAttachmentsDir);
if (isExternalAttachmentsDirReady())
try
{
File[] attachments = mAttachmentsDir.listFiles();
for (File attachment : attachments)
{
if (attachment.exists())
{
attachment.delete();
}
}
if (mAttachmentsDir.exists())
{
mAttachmentsDir.delete();
}
}
catch (Exception e)
{
delete(mExternalAttachmentsDir);
}
try
{
new File(mPath).delete();
@ -437,124 +403,81 @@ public class LocalStore extends Store implements Serializable
}
}
private void delete(File attachmentsDir) {
try {
File[] attachments = attachmentsDir.listFiles();
if (attachments==null)
{
Log.w(K9.LOG_TAG, "Unable to list files: " + attachmentsDir.getAbsolutePath());
}
else
{
for (File attachment : attachments)
{
if (attachment.exists())
{
attachment.delete();
}
}
if (attachmentsDir.exists())
{
attachmentsDir.delete();
}
}
}
catch (Exception e)
{
Log.w(K9.LOG_TAG, null, e);
}
}
public void pruneCachedAttachments() throws MessagingException
{
pruneCachedAttachments(false);
}
/**
* Deletes all cached attachments for the entire store.
*/
public void pruneCachedAttachments(boolean force) throws MessagingException
{
if (force)
{
ContentValues cv = new ContentValues();
cv.putNull("content_uri");
mDb.update("attachments", cv, null, null);
}
pruneCachedAttachments(force, mInternalAttachmentsDir);
if (isExternalAttachmentsDirReady())
File[] files = mAttachmentsDir.listFiles();
for (File file : files)
{
pruneCachedAttachments(force, mExternalAttachmentsDir);
}
}
/**
* Deletes all cached attachments for the entire store.
*/
private void pruneCachedAttachments(boolean force, File attachmentsDir) throws MessagingException
{
File[] files = attachmentsDir.listFiles();
if (files==null)
{
Log.w(K9.LOG_TAG, "Unable to list files: " + attachmentsDir.getAbsolutePath());
}
else
{
for (File file : files)
if (file.exists())
{
if (file.exists())
if (!force)
{
if (!force)
Cursor cursor = null;
try
{
Cursor cursor = null;
try
cursor = mDb.query(
"attachments",
new String[] { "store_data" },
"id = ?",
new String[] { file.getName() },
null,
null,
null);
if (cursor.moveToNext())
{
cursor = mDb.query(
"attachments",
new String[] { "store_data" },
"id = ?",
new String[] { file.getName() },
null,
null,
null);
if (cursor.moveToNext())
if (cursor.getString(0) == null)
{
if (cursor.getString(0) == null)
{
Log.d(K9.LOG_TAG, "Attachment " + file.getAbsolutePath() + " has no store data, not deleting");
/*
* If the attachment has no store data it is not recoverable, so
* we won't delete it.
*/
continue;
}
}
}
finally
{
if (cursor != null)
{
cursor.close();
Log.d(K9.LOG_TAG, "Attachment " + file.getAbsolutePath() + " has no store data, not deleting");
/*
* If the attachment has no store data it is not recoverable, so
* we won't delete it.
*/
continue;
}
}
}
if (!force)
finally
{
try
if (cursor != null)
{
ContentValues cv = new ContentValues();
cv.putNull("content_uri");
mDb.update("attachments", cv, "id = ?", new String[] { file.getName() });
}
catch (Exception e)
{
/*
* If the row has gone away before we got to mark it not-downloaded that's
* okay.
*/
cursor.close();
}
}
if (!file.delete())
}
if (!force)
{
try
{
file.deleteOnExit();
ContentValues cv = new ContentValues();
cv.putNull("content_uri");
mDb.update("attachments", cv, "id = ?", new String[] { file.getName() });
}
catch (Exception e)
{
/*
* If the row has gone away before we got to mark it not-downloaded that's
* okay.
*/
}
}
if (!file.delete())
{
file.deleteOnExit();
}
}
}
@ -1796,7 +1719,7 @@ public class LocalStore extends Store implements Serializable
* so we copy the data into a cached attachment file.
*/
InputStream in = attachment.getBody().getInputStream();
tempAttachmentFile = File.createTempFile("att", null, getAttachmentsDir());
tempAttachmentFile = File.createTempFile("att", null, mAttachmentsDir);
FileOutputStream out = new FileOutputStream(tempAttachmentFile);
size = IOUtils.copy(in, out);
in.close();
@ -1861,7 +1784,7 @@ public class LocalStore extends Store implements Serializable
if (tempAttachmentFile != null)
{
File attachmentFile = new File(getAttachmentsDir(), Long.toString(attachmentId));
File attachmentFile = new File(mAttachmentsDir, Long.toString(attachmentId));
tempAttachmentFile.renameTo(attachmentFile);
contentUri = AttachmentProvider.getAttachmentUri(
new File(mPath).getName(),
@ -2019,20 +1942,11 @@ public class LocalStore extends Store implements Serializable
long attachmentId = attachmentsCursor.getLong(0);
try
{
File file;
file = new File(mInternalAttachmentsDir, Long.toString(attachmentId));
File file = new File(mAttachmentsDir, Long.toString(attachmentId));
if (file.exists())
{
file.delete();
}
file = new File(mExternalAttachmentsDir, Long.toString(attachmentId));
if (file.exists())
{
file.delete();
}
}
catch (Exception e)
{
@ -2595,6 +2509,14 @@ public class LocalStore extends Store implements Serializable
{
return mApplication.getContentResolver().openInputStream(mUri);
}
catch (FileNotFoundException fnfe)
{
/*
* Since it's completely normal for us to try to serve up attachments that
* have been blown away, we just return an empty stream.
*/
return new ByteArrayInputStream(new byte[0]);
}
catch (IOException ioe)
{
throw new MessagingException("Invalid attachment.", ioe);
@ -2614,73 +2536,4 @@ public class LocalStore extends Store implements Serializable
return mUri;
}
}
private File getAttachmentsDir()
{
if (mStoreAttachmentsOnSdCard)
{
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
if (!mExternalAttachmentsDir.exists())
{
mExternalAttachmentsDir.mkdirs();
}
return mExternalAttachmentsDir;
}
else
{
throw new IllegalStateException("SD card not mounted");
}
}
else {
return mInternalAttachmentsDir;
}
}
public boolean isStoreAttachmentsOnSdCard()
{
return mStoreAttachmentsOnSdCard;
}
public void setStoreAttachmentsOnSdCard(boolean storeAttachmentsOnSdCard)
{
this.mStoreAttachmentsOnSdCard = storeAttachmentsOnSdCard;
if (K9.DEBUG)
{
Log.v(K9.LOG_TAG, "mStoreAttachmentsOnSdCard: " + mStoreAttachmentsOnSdCard);
}
if (storeAttachmentsOnSdCard
&& !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)
&& !mExternalAttachmentsDir.exists())
{
mExternalAttachmentsDir.mkdirs();
}
}
/**
* Checks if the dir is eardy to use and if we need it.
*
* @exception IllegalStateException If the dir is not ready (SD card not mounted)
* and we expect it to be (mStoreAttachmentsOnSdCard is true)
*/
private boolean isExternalAttachmentsDirReady()
{
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
{
if (!mExternalAttachmentsDir.exists())
{
mExternalAttachmentsDir.mkdirs();
}
return true;
}
else if (!mStoreAttachmentsOnSdCard)
{
return false;
}
else
{
throw new IllegalStateException("SD card not mounted");
}
}
}

View File

@ -9,7 +9,6 @@ import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import com.fsck.k9.Account;
@ -157,29 +156,6 @@ public class AttachmentProvider extends ContentProvider
}
}
private File getFile(String dbName, String id)
throws FileNotFoundException
{
try
{
File attachmentsDir = getContext().getDatabasePath(dbName + "_att");
File file = new File(attachmentsDir, id);
if (!file.exists())
{
file = new File("/sdcard" + attachmentsDir.getCanonicalPath().substring("/data".length()), id);
if (!file.exists()) {
throw new FileNotFoundException();
}
}
return file;
}
catch (IOException e)
{
Log.w(K9.LOG_TAG, null, e);
throw new FileNotFoundException(e.getMessage());
}
}
@Override
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException
{
@ -200,9 +176,10 @@ public class AttachmentProvider extends ContentProvider
String type = getType(attachmentUri);
try
{
FileInputStream in = new FileInputStream(getFile(dbName, id));
FileInputStream in = new FileInputStream(
new File(getContext().getDatabasePath(dbName + "_att"), id));
Bitmap thumbnail = createThumbnail(type, in);
thumbnail = Bitmap.createScaledBitmap(thumbnail, width, height, true);
thumbnail = thumbnail.createScaledBitmap(thumbnail, width, height, true);
FileOutputStream out = new FileOutputStream(file);
thumbnail.compress(Bitmap.CompressFormat.PNG, 100, out);
out.close();
@ -218,7 +195,7 @@ public class AttachmentProvider extends ContentProvider
else
{
return ParcelFileDescriptor.open(
getFile(dbName, id),
new File(getContext().getDatabasePath(dbName + "_att"), id),
ParcelFileDescriptor.MODE_READ_ONLY);
}
}