private Property parseProperties() throws ParseException { Property prop; /* * <bmessage-property>::=<bmessage-version-property> * <bmessage-readstatus-property> <bmessage-type-property> * <bmessage-folder-property> <bmessage-version-property>::="VERSION:" * <common-digit>*"."<common-digit>* <CRLF> * <bmessage-readstatus-property>::="STATUS:" 'readstatus' <CRLF> * <bmessage-type-property>::="TYPE:" 'type' <CRLF> * <bmessage-folder-property>::="FOLDER:" 'foldername' <CRLF> */ do { prop = mParser.next(); if (prop.name.equals("VERSION")) { mBmsg.mBmsgVersion = prop.value; } else if (prop.name.equals("STATUS")) { for (Status s : Status.values()) { if (prop.value.equals(s.toString())) { mBmsg.mBmsgStatus = s; break; } } } else if (prop.name.equals("TYPE")) { for (Type t : Type.values()) { if (prop.value.equals(t.toString())) { mBmsg.mBmsgType = t; break; } } } else if (prop.name.equals("FOLDER")) { mBmsg.mBmsgFolder = prop.value; } } while (!prop.equals(BEGIN_VCARD) && !prop.equals(BEGIN_BENV)); return prop; }
private Property parseBody() throws IOException, ParseException { Property prop; /* * <bmessage-content>::= { "BEGIN:BBODY"<CRLF> [<bmessage-body-part-ID> * <CRLF>] <bmessage-body-property> <bmessage-body-content>* <CRLF> * "END:BBODY"<CRLF> } <bmessage-body-part-ID>::="PARTID:" 'Part-ID' * <bmessage-body-property>::=[<bmessage-body-encoding-property>] * [<bmessage-body-charset-property>] * [<bmessage-body-language-property>] * <bmessage-body-content-length-property> * <bmessage-body-encoding-property>::="ENCODING:"'encoding' <CRLF> * <bmessage-body-charset-property>::="CHARSET:"'charset' <CRLF> * <bmessage-body-language-property>::="LANGUAGE:"'language' <CRLF> * <bmessage-body-content-length-property>::= "LENGTH:" <common-digit>* * <CRLF> */ do { prop = mParser.next(); if (prop.name.equals("PARTID")) { } else if (prop.name.equals("ENCODING")) { mBmsg.mBbodyEncoding = prop.value; } else if (prop.name.equals("CHARSET")) { mBmsg.mBbodyCharset = prop.value; } else if (prop.name.equals("LANGUAGE")) { mBmsg.mBbodyLanguage = prop.value; } else if (prop.name.equals("LENGTH")) { try { mBmsg.mBbodyLength = Integer.valueOf(prop.value); } catch (NumberFormatException e) { throw new ParseException("Invalid LENGTH value", mParser.pos()); } } } while (!prop.equals(BEGIN_MSG)); /* * <bmessage-body-content>::={ "BEGIN:MSG"<CRLF> 'message'<CRLF> * "END:MSG"<CRLF> } */ int messageLen = mBmsg.mBbodyLength - MSG_CONTAINER_LEN; int offset = messageLen + CRLF_LEN; int restartPos = mParser.pos() + offset; /* * length is specified in bytes so we need to convert from unicode * string back to bytes array */ String remng = mParser.remaining(); byte[] data = remng.getBytes(); /* restart parsing from after 'message'<CRLF> */ mParser = new BmsgTokenizer(new String(data, offset, data.length - offset), restartPos); prop = mParser.next(true); if (prop != null && prop.equals(END_MSG)) { mBmsg.mMessage = new String(data, 0, messageLen); } else { data = null; /* * now we check if bMessage can be parsed if LENGTH is handled as * number of characters instead of number of bytes */ Log.w(TAG, "byte LENGTH seems to be invalid, trying with char length"); mParser = new BmsgTokenizer(remng.substring(offset)); prop = mParser.next(); if (!prop.equals(END_MSG)) { throw expected(END_MSG); } mBmsg.mMessage = remng.substring(0, messageLen); } prop = mParser.next(); if (!prop.equals(END_BBODY)) { throw expected(END_BBODY); } return mParser.next(); }