Home | History | Annotate | Download | only in map
      1 /*
      2 * Copyright (C) 2013 Samsung System LSI
      3 * Licensed under the Apache License, Version 2.0 (the "License");
      4 * you may not use this file except in compliance with the License.
      5 * You may obtain a copy of the License at
      6 *
      7 *      http://www.apache.org/licenses/LICENSE-2.0
      8 *
      9 * Unless required by applicable law or agreed to in writing, software
     10 * distributed under the License is distributed on an "AS IS" BASIS,
     11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 * See the License for the specific language governing permissions and
     13 * limitations under the License.
     14 */
     15 package com.android.bluetooth.map;
     16 
     17 import java.io.UnsupportedEncodingException;
     18 import java.nio.charset.Charset;
     19 import java.text.SimpleDateFormat;
     20 import java.util.ArrayList;
     21 import java.util.Arrays;
     22 import java.util.Date;
     23 import java.util.Locale;
     24 import java.util.UUID;
     25 
     26 import com.android.bluetooth.map.BluetoothMapSmsPdu.SmsPdu;
     27 
     28 import android.text.util.Rfc822Token;
     29 import android.text.util.Rfc822Tokenizer;
     30 import android.util.Base64;
     31 import android.util.Log;
     32 
     33 
     34 public class BluetoothMapbMessageEmail extends BluetoothMapbMessage {
     35 
     36     private String mEmailBody = null;
     37 
     38     public void setEmailBody(String emailBody) {
     39         this.mEmailBody = emailBody;
     40         this.mCharset = "UTF-8";
     41         this.mEncoding = "8bit";
     42     }
     43 
     44     public String getEmailBody() {
     45         return mEmailBody;
     46     }
     47 
     48     public void parseMsgPart(String msgPart) {
     49         if (mEmailBody == null)
     50             mEmailBody = msgPart;
     51         else
     52             mEmailBody += msgPart;
     53     }
     54 
     55     /**
     56      * Set initial values before parsing - will be called is a message body is found
     57      * during parsing.
     58      */
     59     public void parseMsgInit() {
     60         // Not used for e-mail
     61     }
     62 
     63     public byte[] encode() throws UnsupportedEncodingException
     64     {
     65         ArrayList<byte[]> bodyFragments = new ArrayList<byte[]>();
     66 
     67         /* Store the messages in an ArrayList to be able to handle the different message types in a generic way.
     68          * We use byte[] since we need to extract the length in bytes. */
     69         if(mEmailBody != null) {
     70             String tmpBody = mEmailBody.replaceAll("END:MSG", "/END\\:MSG"); // Replace any occurrences of END:MSG with \END:MSG
     71             bodyFragments.add(tmpBody.getBytes("UTF-8"));
     72         } else {
     73             Log.e(TAG, "Email has no body - this should not be possible");
     74             bodyFragments.add(new byte[0]); // An empty message - this should not be possible
     75         }
     76         return encodeGeneric(bodyFragments);
     77     }
     78 
     79 }
     80