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.util.ArrayList; 19 20 import android.util.Log; 21 22 23 public class BluetoothMapbMessageEmail extends BluetoothMapbMessage { 24 25 private String mEmailBody = null; 26 setEmailBody(String emailBody)27 public void setEmailBody(String emailBody) { 28 this.mEmailBody = emailBody; 29 this.mCharset = "UTF-8"; 30 this.mEncoding = "8bit"; 31 } 32 getEmailBody()33 public String getEmailBody() { 34 return mEmailBody; 35 } 36 parseMsgPart(String msgPart)37 public void parseMsgPart(String msgPart) { 38 if (mEmailBody == null) 39 mEmailBody = msgPart; 40 else 41 mEmailBody += msgPart; 42 } 43 44 /** 45 * Set initial values before parsing - will be called is a message body is found 46 * during parsing. 47 */ parseMsgInit()48 public void parseMsgInit() { 49 // Not used for e-mail 50 } 51 encode()52 public byte[] encode() throws UnsupportedEncodingException 53 { 54 ArrayList<byte[]> bodyFragments = new ArrayList<byte[]>(); 55 56 /* Store the messages in an ArrayList to be able to handle the different message types in a generic way. 57 * We use byte[] since we need to extract the length in bytes. */ 58 if(mEmailBody != null) { 59 String tmpBody = mEmailBody.replaceAll("END:MSG", "/END\\:MSG"); // Replace any occurrences of END:MSG with \END:MSG 60 bodyFragments.add(tmpBody.getBytes("UTF-8")); 61 } else { 62 Log.e(TAG, "Email has no body - this should not be possible"); 63 bodyFragments.add(new byte[0]); // An empty message - this should not be possible 64 } 65 return encodeGeneric(bodyFragments); 66 } 67 68 } 69