Home | History | Annotate | Download | only in email
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.email;
     18 
     19 import com.android.emailcommon.mail.MessagingException;
     20 
     21 import android.content.Context;
     22 
     23 /**
     24  * @return the error message associated with this exception.
     25  */
     26 public class MessagingExceptionStrings {
     27     public static String getErrorString(Context context, MessagingException e) {
     28         return context.getResources().getString(getErrorStringResourceId(e));
     29     }
     30 
     31     /**
     32      * @return the resource ID of the error message associated with this exception.
     33      */
     34     private static int getErrorStringResourceId(MessagingException e) {
     35         switch (e.getExceptionType()) {
     36             case MessagingException.IOERROR:
     37                 return R.string.account_setup_failed_ioerror;
     38             case MessagingException.ATTACHMENT_NOT_FOUND:
     39                 return R.string.attachment_not_found;
     40             case MessagingException.TLS_REQUIRED:
     41                 return R.string.account_setup_failed_tls_required;
     42             case MessagingException.AUTH_REQUIRED:
     43                 return R.string.account_setup_failed_auth_required;
     44             case MessagingException.GENERAL_SECURITY:
     45                 return R.string.account_setup_failed_security;
     46                 // TODO Generate a unique string for this case, which is the case
     47                 // where the security policy needs to be updated.
     48             case MessagingException.SECURITY_POLICIES_REQUIRED:
     49                 return R.string.account_setup_failed_security;
     50             case MessagingException.ACCESS_DENIED:
     51                 return R.string.account_setup_failed_access_denied;
     52             case MessagingException.CLIENT_CERTIFICATE_ERROR:
     53                 return R.string.account_setup_failed_certificate_inaccessible;
     54         }
     55         return R.string.status_network_error; // default
     56     }
     57 }
     58