Announcement

Collapse
No announcement yet.

HTTP API import VCARD problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • HTTP API import VCARD problem

    I'm doing some migration testing and have hit a snag trying to import vcards using the HTTP-API:

    OX version: 6.14.0 Rev6

    I have the following script (yes, there are many assumptions in the script - this is a test):

    Code:
    #!/usr/bin/perl -w
    
    use strict;
    use Data::Dumper;
    use LWP;
    use JSON -support_by_pp;
    
    my $base = "http://my.server.com/ajax";
    my $response;
    my $browser = LWP::UserAgent->new( );
    my $json = new JSON;
    
    $browser->cookie_jar( {} );
    
    $response = $browser->get("$base/login?action=login&name=my.user@my.server.com&password=nothing");
    my $json_text = $json->decode($response->{_content});
    my $session = $json_text->{session};
    
    $response = $browser->post("$base/import?action=VCARD&session=$session&folder=26",['data'=>['/tmp/vcard']],'Content-type'=>'multipart/form-data');
    print Dumper $response;
    And the following contents of /tmp/vcard:

    Code:
    BEGIN:VCARD
    FN:John Smith
    EMAIL;PREF;INTERNET:john.smith@nowheere.com
    END:VCARD
    Running the script gives the following result:

    Code:
    $VAR1 = bless( {
                     '_protocol' => 'HTTP/1.1',
                     '_content' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"><html><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript"> function callback(arg) { parent.callback_import(arg); }; callback({"data":[{"code":"I_E-0605","error_id":"1767232792-54","category":1,"error_params":["[B@68f507d2"],"error":"Could not recognize format of the following data: %s"}]});</script></head></html> ',
                     '_rc' => '200',
                     '_headers' => bless( {
                                            'connection' => 'close',
                                            'client-response-num' => 1,
                                            'cache-control' => 'no-store, no-cache, must-revalidate,post-check=0, pre-check=0,no-store, no-cache, must-revalidate,post-check=0, pre-check=0',
                                            'date' => 'Thu, 10 Dec 2009 14:44:04 GMT',
                                            'vary' => 'Accept-Encoding',
                                            'client-peer' => '217.160.4.202:80',
                                            'client-date' => 'Thu, 10 Dec 2009 14:44:04 GMT',
                                            'pragma' => 'no-cache,no-cache',
                                            'content-type' => 'text/html; charset=UTF-8',
                                            'client-transfer-encoding' => [
                                                                            'chunked'
                                                                          ],
                                            'expires' => 'Sat, 06 May 1995 12:00:00 GMT,Sat, 06 May 1995 12:00:00 GMT'
                                          }, 'HTTP::Headers' ),
                     '_msg' => 'OK',
                     '_request' => bless( {
                                            '_content' => '--xYzZY
    Content-Disposition: form-data; name="data"; filename="vcard"
    Content-Type: text/plain
    
    BEGIN:VCARD
    FN:John Smith
    EMAIL;PREF;INTERNET:john.smith@nowheere.com
    END:VCARD
    
    --xYzZY--
    ',
                                            '_uri' => bless( do{\(my $o = 'http://mail.b7fc.com/ajax/import?action=VCARD&session=dc8e5ea5a5fa4014a513ae53276981ea&folder=26')}, 'URI::http' ),
                                            '_headers' => bless( {
                                                                   'cookie2' => '$Version="1"',
                                                                   'user-agent' => 'libwww-perl/5.834',
                                                                   'content-type' => 'multipart/form-data; boundary=xYzZY',
                                                                   'cookie' => 'open-xchange-session-dc8e5ea5a5fa4014a513ae53276981ea=4790dd6bf2bf4c08bc29cf6c9b34b6f1; JSESSIONID=6376af80332a43789baa088e905bbccd.APP1',
                                                                   'content-length' => 197
                                                                 }, 'HTTP::Headers' ),
                                            '_method' => 'POST',
                                            '_uri_canonical' => $VAR1->{'_request'}{'_uri'}
                                          }, 'HTTP::Request' )
                   }, 'HTTP::Response' );
    (decoded JSON string for readability)
    Code:
              
    'data' => [
      {
        'error' => 'Could not recognize format of the following data: %s',
        'category' => 1,
        'error_params' => [
          '[B@24820846'
        ],
        'error_id' => '1767232792-42',
        'code' => 'I_E-0605'
      }
    ]
    error_params changes with each call even though the data is static.

    The following entries occur in open-xchange.log.0:

    Code:
    Dec 10, 2009 2:38:13 PM com.openexchange.sessiond.impl.SessionHandler addSession
    INFO: Session created. ID: 29d4c5904edb45338c7c673e97b4f219, Context: 1008, User: 3
    Dec 10, 2009 2:38:13 PM com.openexchange.groupware.importexport.importers.VCardImporter importData
    SEVERE: Could not recognize format of the following VCard data: [66, 69, 71, 73, 78, 58, 86, 67, 65, 82, 68, 13, 10, 70, 78, 58, 74, 111, 104, 110, 32, 83, 109, 105, 116, 104, 13, 10, 69, 77, 65, 73, 76, 59, 80, 82, 69, 70, 59, 73, 78, 84, 69, 82, 78, 69, 84, 58, 106, 111, 104, 110, 46, 115, 109, 105, 116, 104, 64, 110, 111, 119, 104, 101, 101, 114, 101, 46, 99, 111, 109, 13, 10, 69, 78, 68, 58, 86, 67, 65, 82, 68, 13, 10]
    The data corresponds to the ASCII characters that make up the VCARD submitted.

    Anyone any ideas......?

  • #2
    Hi,

    this error does not seem to be related to the way you import the data but to the content. Are you sure the vcard is valid?

    Greetings

    Comment


    • #3
      Originally posted by Martin Braun View Post
      Hi,

      this error does not seem to be related to the way you import the data but to the content. Are you sure the vcard is valid?

      Greetings
      That was my first thought. I've tried other VCARD files, even down to a basic one with just a name.

      If I use invalid attributes or send anything other than a VCARD file OX recognises this and gives a different error, so it's not the format.

      This actually adds to my confusion; OX is clearly parsing the VCARD; if I put invalid attributes in there it complains.

      What I also don't understand is why the error text given by OX (error_params) is different each time given that the data is constant.

      One thought I had is that OX is expecting a specific attribute that's missing, but I'm not sure what that would be.
      Last edited by pborg; 12-13-2009, 09:00 AM.

      Comment


      • #4
        From RFC 2426 (page 28):
        A vCard object MUST include the VERSION, FN and N types.
        I guess we have no default for the case when VERSION is missing.

        Comment


        • #5
          I think Viktor is onto the problem. The version is needed because you can nest several contacts into one vCard file and they may have different versions.
          Of course, in that case we could guess or default to one type and just miss some info. But:

          You can actually mix vCards and iCal in one file (may sound theoretical, but with hCard, you'll see that a lot). And in this case, defaulting is not a good idea, so there is no way around the version info.

          If you look at the source code, you'll find the logic for that in com.openexchange.tools.versit.filetokenizer.VCardT okenizer

          Comment


          • #6
            Originally posted by Viktor Pracht View Post
            From RFC 2426 (page 28):

            I guess we have no default for the case when VERSION is missing.
            Originally posted by Tobias Prinz View Post
            I think Viktor is onto the problem. The version is needed because you can nest several contacts into one vCard file and they may have different versions.
            Thanks for the suggestion but already been there. VERSION is an unsupported tag in Open-Xchange, see: http://www.open-xchange.com/wiki/ind...d_ICal_support

            This is one of the first problems I hit as needless to say all the exported VCARDS I have contain VERSION tags. The HTTP-API threw an error and refused the card.

            The current situation I'm in is as a result of trimming all unsupported fields. I've also tried adding an N field (and various others) - no joy.

            Other suggestions welcome!
            Last edited by pborg; 12-20-2009, 11:13 AM.

            Comment


            • #7
              Version... unsupported? Hmm. To paraphrase Dilbert: "give me ten minutes and check OXPedia".

              *cough* Of course it is supported. Now.

              Seriously, though: Thanks for showing this error in the documentation. This was probably meant to say "OX has no equivalent for the VERSION element" (if you import a v2 VCard, we'll not return it as that necessarily), not "OX does not support the VERSION element". Good catch.

              Comment


              • #8
                Thanks for that - it's helped me to crack the problem.

                The naughty application doing the exporting is marking the VCARD as v3.0 when in fact it's 2.1 - EMAIL;PREF;INTERNET: is 2.1 whereas 3.0 would be EMAIL;TYPE=PREF,INTERNET

                This only showed up when putting the VERSION entry back in the VCARD; I'd removed it after reading the documentation the first time I got any kind of error

                With it back in I received the error (with a mildly amusing typo):

                Code:
                SEVERE: cannot parse contact object
                com.openexchange.tools.versit.VersitException: Errot at line 4, column 16: Incomplete object
                which at least told me where to look. Investigating the VCARD format to find the cause highlighted the 2.1/3.0 difference.

                Thanks for your help.
                Last edited by pborg; 12-20-2009, 03:38 PM.

                Comment

                Working...
                X