• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.util.Log;
18 
19 import java.io.UnsupportedEncodingException;
20 import java.util.ArrayList;
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 
37     @Override
parseMsgPart(String msgPart)38     public void parseMsgPart(String msgPart) {
39         if (mEmailBody == null) {
40             mEmailBody = msgPart;
41         } else {
42             mEmailBody += msgPart;
43         }
44     }
45 
46     /**
47      * Set initial values before parsing - will be called is a message body is found
48      * during parsing.
49      */
50     @Override
parseMsgInit()51     public void parseMsgInit() {
52         // Not used for e-mail
53     }
54 
55     @Override
encode()56     public byte[] encode() throws UnsupportedEncodingException {
57         ArrayList<byte[]> bodyFragments = new ArrayList<byte[]>();
58 
59         /* Store the messages in an ArrayList to be able to handle the different message types in
60          a generic way.
61          * We use byte[] since we need to extract the length in bytes. */
62         if (mEmailBody != null) {
63             String tmpBody = mEmailBody.replaceAll("END:MSG",
64                     "/END\\:MSG"); // Replace any occurrences of END:MSG with \END:MSG
65             bodyFragments.add(tmpBody.getBytes("UTF-8"));
66         } else {
67             Log.e(TAG, "Email has no body - this should not be possible");
68             bodyFragments.add(new byte[0]); // An empty message - this should not be possible
69         }
70         return encodeGeneric(bodyFragments);
71     }
72 
73 }
74