'ds' did not have expected number of elements

iuri_oob
2006-07-19
2013-04-03
  • iuri_oob

    iuri_oob - 2006-07-19

    why?...

     
    • niknah

      niknah - 2006-08-16

      Me too. When I run gmailer4j it says the protocol may have changed.

       
    • Arvis

      Arvis - 2006-08-18

      Same here. Might have to switch to python and use libgmail.

       
    • Curly

      Curly - 2006-09-09

      I think the developer has given up on this project.

       
    • Curly

      Curly - 2006-09-09

      There's a bug in the GMConnector.  In the section of code below, the number of items my connection returns is 3, not 7.  It's fairly trivial to change this if you know java.

                          if (tmpArray.size() == 7) {
                              gminfo.put("stdbox.inbox", (String) tmpArray.get(0)); //$NON-NLS-1$
                              gminfo.put("stdbox.starred", (String)
                              tmpArray.get(1)); //$NON-NLS-1$
                              gminfo.put("stdbox.sent", (String) tmpArray.get(2));
                              //$NON-NLS-1$
                              gminfo.put("stdbox.drafts", (String) tmpArray.get(3)); //$NON-NLS-1$
                              gminfo.put("stdbox.all", (String) tmpArray.get(4));
                              //$NON-NLS-1$
                              gminfo.put("stdbox.spam", (String) tmpArray.get(5)); //$NON-NLS-1$
                              gminfo.put("stdbox.trash", (String) tmpArray.get(6));
                              //$NON-NLS-1$
                          } else {
                              logger.warn("DataPacket error: 'ds' did not have expected number of elements (7)."); //$NON-NLS-1$
                              throw new ParsePacketException("'ds' did not have expected number of elements (7).", //$NON-NLS-1$
                                      input);
                          }

       
    • kichiro7

      kichiro7 - 2006-12-10

      Hello!
      Thanks for the precious information. I've tried to change the number,
      7 to 3, and changed the source code as shown below.
      However, I became unable to login gmail. And still I have the same
      problem. Could you anyone let me know how I can fix this problem more
      concretely!

      if (tmpArray.size() == 3) {
      gminfo.put("stdbox.inbox", (String) tmpArray.get(0)); //$NON-NLS-1$
      gminfo.put("stdbox.starred", (String)
      tmpArray.get(1)); //$NON-NLS-1$
      gminfo.put("stdbox.sent", (String) tmpArray.get(2));
      //$NON-NLS-1$
      //gminfo.put("stdbox.drafts", (String) tmpArray.get(3)); //$NON-NLS-1$
      //gminfo.put("stdbox.all", (String) tmpArray.get(4));
      //$NON-NLS-1$
      //gminfo.put("stdbox.spam", (String) tmpArray.get(5)); //$NON-NLS-1$
      //gminfo.put("stdbox.trash", (String) tmpArray.get(6));
      //$NON-NLS-1$
      } else {
      logger.warn("DataPacket error: 'ds' did not have expected number of elements (2)."); //$NON-NLS-1$
      throw new ParsePacketException("'ds' did not have expected number of elements (2).", //$NON-NLS-1$
      input);
      }

       
    • danst150

      danst150 - 2007-10-22

      I am also having the same problems and would like to know if anyone has found a solution????

      Thanks!

       
      • avinpr

        avinpr - 2007-10-22

        Hey guys.

        Here is the function that works for me..its in GMConnector.java where I had to slowly debug some sections to figure out what had changed with the response. Hope it works for u guys too.

        Cheers.

        private GMResponse parseDataPacket(String input)
                    throws ParsePacketException
            {
                Map parseMap = parseData(input);

                GMResponse response = null;
                TreeMap gminfo = new TreeMap();
                TreeMap gmlabel = new TreeMap();
                ArrayList threads = new ArrayList();

                for (Iterator it = parseMap.keySet().iterator(); it.hasNext();)
                {
                    String settingName = (String) it.next();
                    ArrayList tmpArray = (ArrayList) parseMap.get(settingName);

                    try
                    {
                        if (settingName.equals("v")) { //$NON-NLS-1$
                            gminfo.put("version", (String) tmpArray.get(0)); //$NON-NLS-1$
                        }
                        else if (settingName.equals("ds"))
                        { // default searches
                            // //$NON-NLS-1$
                            if (tmpArray.size() == 7)
                            {
                                gminfo.put("stdbox.inbox", (String) tmpArray.get(0)); //$NON-NLS-1$
                                gminfo.put("stdbox.starred", (String) tmpArray.get(1)); //$NON-NLS-1$
                                gminfo.put("stdbox.sent", (String) tmpArray.get(2)); //$NON-NLS-1$
                                gminfo.put("stdbox.drafts", (String) tmpArray.get(3)); //$NON-NLS-1$
                                gminfo.put("stdbox.all", (String) tmpArray.get(4)); //$NON-NLS-1$
                                gminfo.put("stdbox.spam", (String) tmpArray.get(5)); //$NON-NLS-1$
                                gminfo.put("stdbox.trash", (String) tmpArray.get(6)); //$NON-NLS-1$
                            }
                            else if(tmpArray.size() == 1){
                                ArrayList temp = (ArrayList)tmpArray.get(0);
                                ArrayList inbox = (ArrayList)temp.get(0);
                                gminfo.put("stdbox.inbox", (String) inbox.get(1)); //$NON-NLS-1$
                            }
                            else
                            {   if(DEBUG)
                                logger.warn("DataPacket error: 'ds' did not have expected number of elements (7)."); //$NON-NLS-1$
                                throw new ParsePacketException(
                                        "'ds' did not have expected number of elements (7).", //$NON-NLS-1$
                                        input);
                            }
                        }
                        else if (settingName.equals("ct"))
                        { // category(label) list
                            // //$NON-NLS-1$
                            for (Iterator iter = ((ArrayList) tmpArray.get(0))
                                    .iterator(); iter.hasNext();)
                            {
                                ArrayList label = (ArrayList) iter.next();
                                gmlabel.put((String) label.get(0), (String) label
                                        .get(1));
                            }
                        }
                        else if (settingName.equals("qu")) { // quota //$NON-NLS-1$
                            // INFO: Data Item: ["qu","47 MB","1000 MB","5%","#006633"]
                            gminfo.put("quota.mb", (String) tmpArray.get(0)); //$NON-NLS-1$
                            gminfo.put("quota.total", (String) tmpArray.get(1)); //$NON-NLS-1$
                            gminfo.put("quota.percent", (String) tmpArray.get(2)); //$NON-NLS-1$
                        }
                        else if (settingName.equals("sr"))
                        {
                            // response from a sent message
                            gminfo
                                    .put("sendResponse.message", (String) tmpArray
                                            .get(2));
                            gminfo.put("sendResponse.thread", (String) tmpArray.get(3));
                        }
                        else if (settingName.equals("i")) { // invitation //$NON-NLS-1$
                            gminfo.put("invitation", (String) tmpArray.get(0)); //$NON-NLS-1$
                        }
                        else if (settingName.equals("ts"))
                        { // thread status
                            // //$NON-NLS-1$
                            /**
                             * if a packet have "ts", it is a GMStandard type response
                             * (query) Create the object
                             */
                            response = new GMStandard(gminfo, gmlabel, threads);

                            // 15 Feb 05: D(["ts",0,50,3,0,"Inbox","10213b2b249",4,]
                            // ts",0,20,21,0,"Search results for:
                            // Hello","1025e4f50f4",35,,"hello.0"]
                            if (tmpArray.size() >= 8)
                            {
                                gminfo
                                        .put(
                                                "current.box.name", (String) tmpArray.get(4)); //$NON-NLS-1$
                                gminfo
                                        .put(
                                                "current.box.totalthreads", (String) tmpArray.get(2)); //$NON-NLS-1$
                                gminfo
                                        .put(
                                                "current.box.threadsperpage", (String) tmpArray.get(1)); //$NON-NLS-1$
                                gminfo
                                        .put(
                                                "current.box.position", (String) tmpArray.get(0)); //$NON-NLS-1$
                                gminfo
                                        .put(
                                                "current.box.timestamp", (String) tmpArray.get(5)); //$NON-NLS-1$
                                gminfo
                                        .put(
                                                "current.box.totalmsgs", (String) tmpArray.get(6)); //$NON-NLS-1$
                            }
                            else
                            {   if(DEBUG)
                                logger
                                        .warn("DataPacket error: 'ts' did not have expected number of elements (expected=8, actual=" + tmpArray.size() + ")."); //$NON-NLS-1$ //$NON-NLS-2$
                                throw new ParsePacketException(
                                        "'ts' did not have expected number of elements (8).", //$NON-NLS-1$
                                        input);
                            }
                        }
                        else if (settingName.equals("cs"))
                        { // conversation status
                            // //$NON-NLS-1$
                            /**
                             * if a packet have "cs", it is a GMConversion type response
                             * Create the object
                             */
                            response = new GMConversation(gminfo, gmlabel, threads);

                            ((GMConversation) response).setTitle((String) tmpArray
                                    .get(1));
                            ((GMConversation) response).setTotal(Integer
                                    .parseInt((String) tmpArray.get(7)));
                            ((GMConversation) response).setId((String) tmpArray.get(0));
                            ((GMConversation) response).setLabels((ArrayList) tmpArray
                                    .get(4));
                        }
                        else if (settingName.equals("mi"))
                        { // conversation entry
                            // //$NON-NLS-1$
                            /*
                             * As of 15 Feb 05 "mi", 0 0, 1 1, 2 "1024f1c178a90037", 3
                             * 0, 4 "0", 5 "xxxxxx", 6 "xxxxxxxxx@gmail.com", 7 "me", 8
                             * "2/26/05 (3 days ago)", 9 ["xxxxxxxxxxx@gmail.com"], 10
                             * [], 11 [], 12 ["xxxx <xxxxxxxxx@gmail.com>"], 13 "Sat, 26
                             * Feb 2005 15:39:58 +0100", 14 "xxxxxxxxxxxxxxxxx", 15 "",
                             * 16 [], 17 0, 18 , 19 , 20 "Saturday, February 26,
                             * 2005_6:39 AM"]); [ "mi", 0 8, 1 1, 2 "104e5fc86adbd621",
                             * 3 0, 4 "0", 5 "Google �ְT", 6 "Google �ְT", 7
                             * "googlealerts-noreply@google.com", 8 "me", 9 "12:53 am (6
                             * hours ago)", 10 ["siu.ying@gmail.com"], 11 [], 12 [], 13
                             * [], 14 "Jul 5, 2005 12:53 AM", 15 "Google �ְT - ��q�Ȧ�",
                             * 16 "", 17 [], 18 0, 19 , 20 , 21 "Tue Jul 5 2005_12:53
                             * AM", 22 "On 7/5/05, Google �ְT
                             * <googlealerts-noreply@google.com> wrote:", 23 "On 7/5/05,
                             * <b class=gmail_sendername>Google �ְT</b>
                             * &lt;googlealerts-noreply@google.com&gt; wrote:"]
                             */
                            GMConversationEntry entry = new GMConversationEntry();
                            entry.setIndex((String) tmpArray.get(1));
                            entry.setId((String) tmpArray.get(2));
                            entry.setSender((String) tmpArray.get(6));
                            entry.setSender_email(((String) tmpArray.get(7)));

                            entry.setRecv((String) tmpArray.get(8));

                            ArrayList atmp = ((ArrayList) tmpArray.get(10));
                            if (atmp.size() > 0)
                            {
                                entry.setRecv_email((String) atmp.get(0));
                            }
                            else
                            {
                                entry.setRecv_email(""); //$NON-NLS-1$
                            }

                            atmp = ((ArrayList) tmpArray.get(13));
                            if (atmp.size() > 0)
                            {
                                entry.setRecv_email((String) atmp.get(0));
                            }
                            else
                            {
                                entry.setRecv_email(""); //$NON-NLS-1$
                            }

                            entry.setDt_easy((String) tmpArray.get(9));
                            entry.setDt((String) tmpArray.get(14));

                            entry.setSubj((String) tmpArray.get(15));
                            entry.setSnippet((String) tmpArray.get(16));

                            ArrayList attachments = new ArrayList();
                            //logger.info("attachments: " + (ArrayList) tmpArray.get(17)); //$NON-NLS-1$

                            // [[0.1, src.zip, application/x-zip-compressed, 6289], 1]
                            for (Iterator iter = ((ArrayList) tmpArray.get(17))
                                    .iterator(); iter.hasNext();)
                            {
                                Object attachObj = iter.next();
                                if (attachObj.getClass().equals(ArrayList.class))
                                {
                                    HashMap atthHash = new HashMap();
                                    ArrayList atth = (ArrayList) attachObj;
                                    if (atth.size() == 4)
                                    {
                                        atthHash.put("id", atth.get(0)); //$NON-NLS-1$
                                        atthHash.put("filename", atth.get(1)); //$NON-NLS-1$
                                        atthHash.put("type", atth.get(2)); //$NON-NLS-1$
                                        atthHash.put("size", atth.get(3)); //$NON-NLS-1$
                                        attachments.add(atthHash);
                                    }
                                }
                            }
                            entry.setAttachment(attachments);
                            ((GMConversation) response).addEntries(entry);
                            //logger.info("Added entries: " + entry); //$NON-NLS-1$
                        }
                        else if (settingName.equals("di")) { //$NON-NLS-1$
                            // "di",4,0,"ff6da5ba37d95a7",0,"0","??p??v","siu.ying@gmail.com",
                            // "","2:50am (2 hours
                            // ago)","aaaaaaaaaaaaaaa@gmail.com","","","??p??v
                            // \&lt;siu.ying@gmail.com\&gt;","Wed, 6 Oct 2004 17:50:38
                            // +0800","","",[],1,"","aaaaaaaaaaaaaaaaaa\n"]
                            GMConversationEntry entry = new GMConversationEntry();
                            entry.setIndex((String) tmpArray.get(1));
                            entry.setId((String) tmpArray.get(2));
                            entry.setSender((String) tmpArray.get(5));
                            entry.setSender_email(((String) tmpArray.get(6)));

                            entry.setRecv((String) tmpArray.get(7));
                            entry.setRecv_email(((String) tmpArray.get(9)));
                            entry.setReply_email(((String) tmpArray.get(12)));

                            entry.setDt_easy((String) tmpArray.get(8));
                            entry.setDt((String) tmpArray.get(13));

                            entry.setSubj((String) tmpArray.get(14));
                            entry.setSnippet((String) tmpArray.get(15));
                            entry.appendBody((String) tmpArray.get(19));

                            ArrayList attachments = new ArrayList();

                            // [[0.1, src.zip, application/x-zip-compressed, 6289], 1]
                            for (Iterator iter = ((ArrayList) tmpArray.get(16))
                                    .iterator(); iter.hasNext();)
                            {
                                Object attachObj = iter.next();
                                if (attachObj.getClass().equals(ArrayList.class))
                                {
                                    HashMap atthHash = new HashMap();
                                    ArrayList atth = (ArrayList) attachObj;
                                    atthHash.put("id", atth.get(0)); //$NON-NLS-1$
                                    atthHash.put("filename", atth.get(1)); //$NON-NLS-1$
                                    atthHash.put("type", atth.get(2)); //$NON-NLS-1$
                                    atthHash.put("size", atth.get(3)); //$NON-NLS-1$
                                    attachments.add(atthHash);
                                }
                            }
                            entry.setAttachment(attachments);
                            ((GMConversation) response).addEntries(entry);
                            //logger.info("Added draft: " + entry); //$NON-NLS-1$

                        }
                        else if (settingName.equals("mb"))
                        { // message body
                            // //$NON-NLS-1$
                            try
                            {
                                String id = (String) tmpArray.get(1);
                                // append the message body we found to last entry
                                if (id != null)
                                {
                                    String body = (String) tmpArray.get(0);

                                    ArrayList entries = ((GMConversation) response)
                                            .getEntries();
                                    try
                                    {
                                        GMConversationEntry entry = (GMConversationEntry) entries
                                                .get(entries.size() - 1);
                                        entry.appendBody(body);
                                        //logger.info("Append body: \&quot;" + body + "\&quot; to entry(" + (entries.size() - 1) + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                                    }
                                    catch (ClassCastException cce)
                                    {   if(DEBUG)
                                        logger.info("Failed adding entries, not Conversatiopn Entries!"); //$NON-NLS-1$
                                    }
                                }
                                else
                                {   if(DEBUG)
                                    logger.info("Skip entry body: id == null "); //$NON-NLS-1$
                                }
                            }
                            catch (NullPointerException npe)
                            {   if(DEBUG)
                                logger.info("NullPointerException while setting body "); //$NON-NLS-1$
                            }
                            catch (ClassCastException cce)
                            {   if(DEBUG)
                                logger
                                        .info("ClassCastException while setting body, possibly wrong data. "); //$NON-NLS-1$
                            }
                            catch (NumberFormatException nfe)
                            {   if(DEBUG)
                                logger
                                        .info("NumberFormatException while setting body, possibly wrong data "); //$NON-NLS-1$
                            }
                        }
                        else if (settingName.equals("t"))
                        { // threads (message lists)
                            // //$NON-NLS-1$
                            // create array to store message listing
                            for (Iterator iter = tmpArray.iterator(); iter.hasNext();)
                            {
                                ArrayList msgArray = (ArrayList) iter.next();
                                GMThread msg = new GMThread();
                                if(msgArray.get(0).getClass().getName().equals("java.util.ArrayList"))
                                    msgArray = (ArrayList)msgArray.get(0);
                                msg.setThreadID((String) msgArray.get(0));
                                msg.setRead(((String) msgArray.get(1)).equals("1")?false: true); // Gmail
                                // reports
                                // isUnread
                                // so
                                // we
                                // swap
                                // //$NON-NLS-1$
                                msg.setStarred(((String) msgArray.get(2)).equals("1") ? true : false); //$NON-NLS-1$
                                msg.setDateHtml((String) msgArray.get(3));
                                msg.setAuthorsHtml((String) msgArray.get(4));
                                msg.setFlags((String) msgArray.get(5));
                                msg.setSubjectHtml((String) msgArray.get(6));
                                msg.setSnippetHtml((String) msgArray.get(7));
                                msg.setCategories((ArrayList) msgArray.get(8));
                                msg.setAttachHtml((String) msgArray.get(9));
                                msg.setMatchingMessageID((String) msgArray.get(10));
                                threads.add(msg);
                                //logger.info(msg.toString());
                            }

                        }
                        else if (settingName.equals("ft")) { //$NON-NLS-1$
                            // message from gmail, ignore it
                            if(DEBUG)
                            logger.info("ignored packet: " + settingName + "=" + tmpArray); //$NON-NLS-1$ //$NON-NLS-2$
                        }
                        else
                        {   if(DEBUG)
                            logger.info("unknown packet: " + settingName + "=" + tmpArray); //$NON-NLS-1$ //$NON-NLS-2$
                        }
                    }
                    catch (ClassCastException ce)
                    {   if(DEBUG)
                        logger.warn("failed parsing packet (" + settingName + ") ClassCastException " + ce.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
                        ce.printStackTrace();
                        throw new ParsePacketException(
                                "failed parsing label packet (" + settingName + ") ClassCastException " + ce.getMessage(), //$NON-NLS-1$ //$NON-NLS-2$
                                input);
                    }
                    catch (NullPointerException ne)
                    {   if(DEBUG)
                        logger.warn("failed parsing packet (" + settingName + ") NullPointerException " + ne.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
                        ne.printStackTrace();
                        throw new ParsePacketException(
                                "failed parsing label packet (" + settingName + ") NullPointerException " + ne.getMessage(), //$NON-NLS-1$ //$NON-NLS-2$
                                input);
                    }
                    catch (ArrayIndexOutOfBoundsException ae)
                    {   if(DEBUG)
                        logger
                                .warn("failed parsing packet (" + settingName + ") ArrayIndexOutOfBoundsException " + ae.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
                        throw new ParsePacketException(
                                "failed parsing label packet (" + settingName + ") ArrayIndexOutOfBoundsException " + ae.getMessage(), //$NON-NLS-1$ //$NON-NLS-2$
                                input);
                    }
                }

                if (response == null)
                {   if(DEBUG)
                    logger.warn("Message: " + input); //$NON-NLS-1$
                    throw new ParsePacketException("Unknown message type!", input); //$NON-NLS-1$
                }

                return response;
            }

         
    • danst150

      danst150 - 2007-10-23

      Hi avinpr,

      Thanks for your quick reply. I am still a bit confused though..

      How exactly did you resolve this problem?

      Are you calling - GMConnector.parseDataPacket(); instead of GMConnector.request() ???

      If you are then what are you passing in as the (String) Input?

      Cheers!

       

Log in to post a comment.