Remove unused code

This commit is contained in:
cketti 2020-04-18 19:51:23 +02:00
parent c8a2319699
commit d70564e423
27 changed files with 2 additions and 589 deletions

View file

@ -66,10 +66,6 @@ public class Account implements BaseAccount, StoreConfig {
this.setting = setting;
}
public String preferenceString() {
return Integer.toString(setting);
}
public static DeletePolicy fromInt(int initialSetting) {
for (DeletePolicy policy: values()) {
if (policy.setting == initialSetting) {
@ -275,7 +271,6 @@ public class Account implements BaseAccount, StoreConfig {
return description;
}
@Override
public synchronized void setDescription(String description) {
this.description = description;
}
@ -316,7 +311,6 @@ public class Account implements BaseAccount, StoreConfig {
return identities.get(0).getEmail();
}
@Override
public synchronized void setEmail(String email) {
Identity newIdentity = identities.get(0).withEmail(email);
identities.set(0, newIdentity);

View file

@ -2,8 +2,6 @@ package com.fsck.k9;
public interface BaseAccount {
String getEmail();
void setEmail(String email);
String getDescription();
void setDescription(String description);
String getUuid();
}

View file

@ -1,150 +0,0 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.fsck.k9;
import java.util.Timer;
import java.util.TimerTask;
import android.os.Handler;
import timber.log.Timber;
/**
* This class used to "throttle" a flow of events.
*
* When {@link #onEvent()} is called, it calls the callback in a certain timeout later.
* Initially {@link #minTimeout} is used as the timeout, but if it gets multiple {@link #onEvent}
* calls in a certain amount of time, it extends the timeout, until it reaches {@link #maxTimeout}.
*
* This class is primarily used to throttle content changed events.
*/
public class Throttle {
private static final int TIMEOUT_EXTEND_INTERVAL = 500;
private static final Timer TIMER = new Timer();
private final Clock clock;
private final Timer timer;
private final String name;
private final Handler handler;
private final Runnable callback;
private final int minTimeout;
private final int maxTimeout;
private int currentTimeout;
/** When {@link #onEvent()} was last called. */
private long lastEventTime;
private MyTimerTask runningTimerTask;
/** Constructor that takes custom timeout */
public Throttle(String name, Runnable callback, Handler handler,int minTimeout,
int maxTimeout) {
this(name, callback, handler, minTimeout, maxTimeout, Clock.INSTANCE, TIMER);
}
/** Constructor for tests */
private Throttle(String name, Runnable callback, Handler handler, int minTimeout,
int maxTimeout, Clock clock, Timer timer) {
if (maxTimeout < minTimeout) {
throw new IllegalArgumentException();
}
this.name = name;
this.callback = callback;
this.clock = clock;
this.timer = timer;
this.handler = handler;
this.minTimeout = minTimeout;
this.maxTimeout = maxTimeout;
currentTimeout = this.minTimeout;
}
private boolean isCallbackScheduled() {
return runningTimerTask != null;
}
public void cancelScheduledCallback() {
if (runningTimerTask != null) {
Timber.d("Throttle: [%s] Canceling scheduled callback", name);
runningTimerTask.cancel();
runningTimerTask = null;
}
}
private void updateTimeout() {
final long now = clock.getTime();
if ((now - lastEventTime) <= TIMEOUT_EXTEND_INTERVAL) {
currentTimeout *= 2;
if (currentTimeout >= maxTimeout) {
currentTimeout = maxTimeout;
}
Timber.d("Throttle: [%s] Timeout extended %d", name, currentTimeout);
} else {
currentTimeout = minTimeout;
Timber.d("Throttle: [%s] Timeout reset to %d", name, currentTimeout);
}
lastEventTime = now;
}
public void onEvent() {
Timber.d("Throttle: [%s] onEvent", name);
updateTimeout();
if (isCallbackScheduled()) {
Timber.d("Throttle: [%s] callback already scheduled", name);
} else {
Timber.d("Throttle: [%s] scheduling callback", name);
runningTimerTask = new MyTimerTask();
timer.schedule(runningTimerTask, currentTimeout);
}
}
/**
* Timer task called on timeout,
*/
private class MyTimerTask extends TimerTask {
private boolean mCanceled;
@Override
public void run() {
handler.post(new HandlerRunnable());
}
@Override
public boolean cancel() {
mCanceled = true;
return super.cancel();
}
private class HandlerRunnable implements Runnable {
@Override
public void run() {
runningTimerTask = null;
if (!mCanceled) { // This check has to be done on the UI thread.
Timber.d("Throttle: [%s] Kicking callback", name);
callback.run();
}
}
}
}
}

View file

@ -5,7 +5,6 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Locale;
import timber.log.Timber;
@ -13,61 +12,6 @@ import org.apache.commons.io.IOUtils;
public class FileHelper {
/**
* Regular expression that represents characters we won't allow in file names.
*
* <p>
* Allowed are:
* <ul>
* <li>word characters (letters, digits, and underscores): {@code \w}</li>
* <li>spaces: {@code " "}</li>
* <li>special characters: {@code !}, {@code #}, {@code $}, {@code %}, {@code &}, {@code '},
* {@code (}, {@code )}, {@code -}, {@code @}, {@code ^}, {@code `}, <code>&#123;</code>,
* <code>&#125;</code>, {@code ~}, {@code .}, {@code ,}</li>
* </ul></p>
*
* @see #sanitizeFilename(String)
*/
private static final String INVALID_CHARACTERS = "[^\\w !#$%&'()\\-@\\^`{}~.,]";
/**
* Invalid characters in a file name are replaced by this character.
*
* @see #sanitizeFilename(String)
*/
private static final String REPLACEMENT_CHARACTER = "_";
/**
* Creates a unique file in the given directory by appending a hyphen
* and a number to the given filename.
*/
public static File createUniqueFile(File directory, String filename) {
File file = new File(directory, filename);
if (!file.exists()) {
return file;
}
// Get the extension of the file, if any.
int index = filename.lastIndexOf('.');
String name;
String extension;
if (index != -1) {
name = filename.substring(0, index);
extension = filename.substring(index);
} else {
name = filename;
extension = "";
}
for (int i = 2; i < Integer.MAX_VALUE; i++) {
file = new File(directory, String.format(Locale.US, "%s-%d%s", name, i, extension));
if (!file.exists()) {
return file;
}
}
return null;
}
public static void touchFile(final File parentDir, final String name) {
final File file = new File(parentDir, name);
try {
@ -200,16 +144,4 @@ public class FileHelper {
Timber.w("cannot delete %s", fromDir.getAbsolutePath());
}
}
/**
* Replace characters we don't allow in file names with a replacement character.
*
* @param filename
* The original file name.
*
* @return The sanitized file name containing only allowed characters.
*/
public static String sanitizeFilename(String filename) {
return filename.replaceAll(INVALID_CHARACTERS, REPLACEMENT_CHARACTER);
}
}

View file

@ -1,25 +1,13 @@
package com.fsck.k9.helper;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
/**
* Wraps the java.net.URLDecoder to avoid unhelpful checked exceptions.
* Wraps the java.net.URLEncoder to avoid unhelpful checked exceptions.
*/
public class UrlEncodingHelper {
public static String decodeUtf8(String s) {
try {
return URLDecoder.decode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
/*
* This is impossible, UTF-8 is always supported
*/
throw new RuntimeException("UTF-8 not found");
}
}
public static String encodeUtf8(String s) {
try {
return URLEncoder.encode(s, "UTF-8");

View file

@ -12,13 +12,10 @@ import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import android.os.Looper;
import android.text.Editable;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.TextView;
import org.apache.james.mime4j.util.MimeUtil;
import timber.log.Timber;
public class Utility {
@ -48,15 +45,6 @@ public class Utility {
return false;
}
public static boolean isAnyMimeType(String o, String... a) {
for (String element : a) {
if (MimeUtil.isSameMimeType(element, o)) {
return true;
}
}
return false;
}
public static boolean arrayContainsAny(Object[] a, Object... o) {
for (Object element : a) {
if (arrayContains(o, element)) {
@ -103,10 +91,6 @@ public class Utility {
}
public static boolean requiredFieldValid(Editable s) {
return s != null && s.length() > 0;
}
public static boolean domainFieldValid(EditText view) {
if (view.getText() != null) {
String s = view.getText().toString();
@ -311,16 +295,4 @@ public class Utility {
return null;
}
/**
* @return a {@link Handler} tied to the main thread.
*/
public static Handler getMainThreadHandler() {
if (sMainThreadHandler == null) {
// No need to synchronize -- it's okay to create an extra Handler, which will be used
// only once and then thrown away.
sMainThreadHandler = new Handler(Looper.getMainLooper());
}
return sMainThreadHandler;
}
}

View file

@ -51,8 +51,4 @@ abstract class BinaryAttachmentBody implements Body {
public void setEncoding(String encoding) throws MessagingException {
mEncoding = encoding;
}
public String getEncoding() {
return mEncoding;
}
}

View file

@ -14,14 +14,4 @@ public class UnavailableStorageException extends MessagingException {
public UnavailableStorageException(String message, boolean perm) {
super(message, perm);
}
public UnavailableStorageException(String message, Throwable throwable) {
// consider this exception as permanent failure by default
this(message, true, throwable);
}
public UnavailableStorageException(String message, boolean perm, Throwable throwable) {
super(message, perm, throwable);
}
}

View file

@ -19,11 +19,6 @@ package com.fsck.k9.mailstore.util;
* Furthermore the header Content-Transfer-Encoding MUST NOT BE Quoted-Printable
* (see RFC3676 paragraph 4.2).(In fact this happens often for non 7bit messages).
* </li>
* <li>When encoding the input text will be changed eliminating every space found before CRLF,
* otherwise it won't be possible to recognize hard breaks from soft breaks.
* In this scenario encoding and decoding a message will not return a message identical to
* the original (lines with hard breaks will be trimmed)
* </li>
* </ul>
*/
public final class FlowedMessageUtils {
@ -31,8 +26,6 @@ public final class FlowedMessageUtils {
private static final char RFC2646_QUOTE = '>';
private static final String RFC2646_SIGNATURE = "-- ";
private static final String RFC2646_CRLF = "\r\n";
private static final String RFC2646_FROM = "From ";
private static final int RFC2646_WIDTH = 78;
private FlowedMessageUtils() {
// this class cannot be instantiated
@ -106,84 +99,4 @@ public final class FlowedMessageUtils {
return result.toString();
}
/**
* Encodes a text (using standard with).
*/
public static String flow(String text, boolean delSp) {
return flow(text, delSp, RFC2646_WIDTH);
}
/**
* Decodes a text.
*/
public static String flow(String text, boolean delSp, int width) {
StringBuilder result = new StringBuilder();
String[] lines = text.split("\r\n|\n", -1);
for (int i = 0; i < lines.length; i ++) {
String line = lines[i];
boolean notempty = line.length() > 0;
int quoteDepth = 0;
while (quoteDepth < line.length() && line.charAt(quoteDepth) == RFC2646_QUOTE) quoteDepth ++;
if (quoteDepth > 0) {
if (quoteDepth + 1 < line.length() && line.charAt(quoteDepth) == RFC2646_SPACE) line = line.substring(quoteDepth + 1);
else line = line.substring(quoteDepth);
}
while (notempty) {
int extra = 0;
if (quoteDepth == 0) {
if (line.startsWith("" + RFC2646_SPACE) || line.startsWith("" + RFC2646_QUOTE) || line.startsWith(RFC2646_FROM)) {
line = "" + RFC2646_SPACE + line;
extra = 1;
}
} else {
line = RFC2646_SPACE + line;
for (int j = 0; j < quoteDepth; j++) line = "" + RFC2646_QUOTE + line;
extra = quoteDepth + 1;
}
int j = width - 1;
if (j >= line.length()) j = line.length() - 1;
else {
while (j >= extra && ((delSp && isAlphaChar(text, j)) || (!delSp && line.charAt(j) != RFC2646_SPACE))) j --;
if (j < extra) {
// Not able to cut a word: skip to word end even if greater than the max width
j = width - 1;
while (j < line.length() - 1 && ((delSp && isAlphaChar(text, j)) || (!delSp && line.charAt(j) != RFC2646_SPACE))) j ++;
}
}
result.append(line.substring(0, j + 1));
if (j < line.length() - 1) {
if (delSp) result.append(RFC2646_SPACE);
result.append(RFC2646_CRLF);
}
line = line.substring(j + 1);
notempty = line.length() > 0;
}
if (i < lines.length - 1) {
// NOTE: Have to trim the spaces before, otherwise it won't recognize soft-break from hard break.
// Deflow of flowed message will not be identical to the original.
while (result.length() > 0 && result.charAt(result.length() - 1) == RFC2646_SPACE) result.deleteCharAt(result.length() - 1);
result.append(RFC2646_CRLF);
}
}
return result.toString();
}
/**
* Checks whether the char is part of a word.
* <p>RFC assert a word cannot be split (even if the length is greater than the maximum length).
*/
public static boolean isAlphaChar(String text, int index) {
// Note: a list of chars is available here:
// http://www.zvon.org/tmRFC/RFC2646/Output/index.html
char c = text.charAt(index);
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9');
}
}
}

View file

@ -93,15 +93,6 @@ public class InsertableHtmlContent implements Serializable {
footerInsertionPoint += content.length();
}
/**
* Remove all quoted content.
*/
public void clearQuotedContent() {
quotedContent.setLength(0);
footerInsertionPoint = 0;
headerInsertionPoint = 0;
}
/**
* Set the inserted content to the specified content. Replaces anything currently in the
* inserted content buffer.

View file

@ -53,7 +53,6 @@ public class SearchAccount implements BaseAccount {
return mEmail;
}
@Override
public synchronized void setEmail(String email) {
this.mEmail = email;
}
@ -63,7 +62,6 @@ public class SearchAccount implements BaseAccount {
return mDescription;
}
@Override
public void setDescription(String description) {
this.mDescription = description;
}

View file

@ -50,15 +50,6 @@ public abstract class K9Activity extends AppCompatActivity {
setSupportActionBar(toolbar);
}
protected void setLayout(View view) {
setContentView(view);
Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar == null) {
throw new IllegalArgumentException("K9 layouts must provide a toolbar with id='toolbar'.");
}
setSupportActionBar(toolbar);
}
public boolean hasPermission(Permission permission) {
return ContextCompat.checkSelfPermission(this, permission.permission) == PackageManager.PERMISSION_GRANTED;
}

View file

@ -1,111 +0,0 @@
package com.fsck.k9.activity.misc;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
/**
* Extends {@link AsyncTask} with methods to attach and detach an {@link Activity}.
*
* <p>
* This is necessary to properly handle configuration changes that will restart an activity.
* </p><p>
* <strong>Note:</strong>
* Implementing classes need to make sure they have no reference to the {@code Activity} instance
* that created the instance of that class. So if it's implemented as inner class, it needs to be
* {@code static}.
* </p>
*
* @param <Params>
* see {@link AsyncTask}
* @param <Progress>
* see {@link AsyncTask}
* @param <Result>
* see {@link AsyncTask}
*
* @see #restore(Activity)
* @see #retain()
*/
public abstract class ExtendedAsyncTask<Params, Progress, Result>
extends AsyncTask<Params, Progress, Result> implements NonConfigurationInstance {
protected Activity mActivity;
protected Context mContext;
protected ProgressDialog mProgressDialog;
protected ExtendedAsyncTask(Activity activity) {
mActivity = activity;
mContext = activity.getApplicationContext();
}
/**
* Connect this {@link AsyncTask} to a new {@link Activity} instance after the activity
* was restarted due to a configuration change.
*
* <p>
* This also creates a new progress dialog that is bound to the new activity.
* </p>
*
* @param activity
* The new {@code Activity} instance. Never {@code null}.
*/
@Override
public void restore(Activity activity) {
mActivity = activity;
showProgressDialog();
}
/**
* Detach this {@link AsyncTask} from the {@link Activity} it was bound to.
*
* <p>
* This needs to be called when the current activity is being destroyed during an activity
* restart due to a configuration change.<br/>
* We also have to destroy the progress dialog because it's bound to the activity that's
* being destroyed.
* </p>
*
* @return {@code true} if this instance should be retained; {@code false} otherwise.
*
* @see Activity#onRetainNonConfigurationInstance()
*/
@Override
public boolean retain() {
boolean retain = false;
if (mProgressDialog != null) {
removeProgressDialog();
retain = true;
}
mActivity = null;
return retain;
}
/**
* Creates a {@link ProgressDialog} that is shown while the background thread is running.
*
* <p>
* This needs to store a {@code ProgressDialog} instance in {@link #mProgressDialog} or
* override {@link #removeProgressDialog()}.
* </p>
*/
protected abstract void showProgressDialog();
protected void removeProgressDialog() {
mProgressDialog.dismiss();
mProgressDialog = null;
}
/**
* This default implementation only creates a progress dialog.
*
* <p>
* <strong>Important:</strong>
* Be sure to call {@link #removeProgressDialog()} in {@link AsyncTask#onPostExecute(Object)}.
* </p>
*/
@Override
protected void onPreExecute() {
showProgressDialog();
}
}

View file

@ -29,12 +29,6 @@ public class AccountSetupComposition extends K9Activity {
private RadioButton mAccountSignatureAfterLocation;
private LinearLayout mAccountSignatureLayout;
public static void actionEditCompositionSettings(Activity context, Account account) {
Intent i = new Intent(context, AccountSetupComposition.class);
i.setAction(Intent.ACTION_EDIT);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
context.startActivity(i);
}
public static void actionEditCompositionSettings(Activity context, String accountUuid) {
Intent intent = new Intent(context, AccountSetupComposition.class);

View file

@ -99,10 +99,6 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
context.startActivity(i);
}
public static void actionEditIncomingSettings(Activity context, Account account) {
context.startActivity(intentActionEditIncomingSettings(context, account));
}
public static void actionEditIncomingSettings(Context context, String accountUuid) {
Intent intent = new Intent(context, AccountSetupIncoming.class);
intent.setAction(Intent.ACTION_EDIT);

View file

@ -82,10 +82,6 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
context.startActivity(i);
}
public static void actionEditOutgoingSettings(Context context, Account account) {
context.startActivity(intentActionEditOutgoingSettings(context, account));
}
public static Intent intentActionEditOutgoingSettings(Context context, Account account) {
Intent i = new Intent(context, AccountSetupOutgoing.class);
i.setAction(Intent.ACTION_EDIT);

View file

@ -50,10 +50,6 @@ public class AttachmentView extends FrameLayout implements OnClickListener {
attachmentType = findViewById(R.id.attachment_type);
}
public AttachmentViewInfo getAttachment() {
return attachment;
}
public void enableButtons() {
setEnabled(true);
saveButton.setVisibility(View.INVISIBLE);

View file

@ -1,7 +0,0 @@
package com.fsck.k9.backend.api;
import com.fsck.k9.mail.Message;
public interface MessageRemovalListener {
void messageRemoved(Message message);
}

View file

@ -98,28 +98,10 @@ public class Address implements Serializable {
return mAddress.substring(hostIdx + 1);
}
public void setAddress(String address) {
if (address == null) {
throw new IllegalArgumentException("address");
}
this.mAddress = address;
}
public String getPersonal() {
return mPersonal;
}
public void setPersonal(String newPersonal) {
String personal = newPersonal;
if ("".equals(personal)) {
personal = null;
}
if (personal != null) {
personal = personal.trim();
}
this.mPersonal = personal;
}
/**
* Parse a comma separated list of email addresses in human readable format and return an
* array of Address objects, RFC-822 encoded.

View file

@ -22,6 +22,4 @@ public abstract class BodyPart implements Part {
public void setParent(Multipart parent) {
this.parent = parent;
}
public abstract void setEncoding(String encoding) throws MessagingException;
}

View file

@ -88,7 +88,6 @@ public class MimeBodyPart extends BodyPart {
this.mBody = body;
}
@Override
public void setEncoding(String encoding) throws MessagingException {
if (mBody != null) {
mBody.setEncoding(encoding);

View file

@ -15,10 +15,4 @@ public interface StoreConfig {
boolean isAllowRemoteSearch();
boolean isRemoteSearchFullText();
boolean isPushPollOnConnect();
int getDisplayCount();
int getIdleRefreshMinutes();
}

View file

@ -91,7 +91,6 @@ class ImapConnection {
private Exception stacktraceForClose;
private boolean open = false;
private boolean retryXoauth2WithNewToken = true;
private int lineLengthLimit;
public ImapConnection(ImapSettings settings, TrustedSocketFactory socketFactory,
@ -772,11 +771,6 @@ class ImapConnection {
return responses;
}
public List<ImapResponse> readStatusResponse(String tag, String commandToLog, UntaggedHandler untaggedHandler)
throws IOException, NegativeImapResponseException {
return responseParser.readStatusResponse(tag, commandToLog, getLogId(), untaggedHandler);
}
public String sendSaslIrCommand(String command, String initialClientResponse, boolean sensitive)
throws IOException, MessagingException {
try {
@ -856,13 +850,6 @@ class ImapConnection {
}
}
protected void setReadTimeout(int millis) throws SocketException {
Socket sock = socket;
if (sock != null) {
sock.setSoTimeout(millis);
}
}
private ImapResponse readContinuationResponse(String tag) throws IOException, MessagingException {
ImapResponse response;
do {

View file

@ -1,12 +0,0 @@
package com.fsck.k9.mail.store.imap;
import java.io.IOException;
import java.util.List;
import com.fsck.k9.mail.MessagingException;
interface ImapSearcher {
List<ImapResponse> search() throws IOException, MessagingException;
}

View file

@ -32,7 +32,5 @@ interface ImapSettings {
void setPathDelimiter(String delimiter);
String getCombinedPrefix();
void setCombinedPrefix(String prefix);
}

View file

@ -401,11 +401,6 @@ public class ImapStore {
pathDelimiter = delimiter;
}
@Override
public String getCombinedPrefix() {
return combinedPrefix;
}
@Override
public void setCombinedPrefix(String prefix) {
combinedPrefix = prefix;

View file

@ -79,11 +79,6 @@ class SimpleImapSettings implements ImapSettings {
pathDelimiter = delimiter;
}
@Override
public String getCombinedPrefix() {
return combinedPrefix;
}
@Override
public void setCombinedPrefix(String prefix) {
combinedPrefix = prefix;