Handles send intents from the Contacts app, retrieving a contact as a VCARD.
976994
private void encodeFromStreamExtra(Intent intent) throws WriterException {
    format = BarcodeFormat.QR_CODE;
    Bundle bundle = intent.getExtras();
    if (bundle == null) {
      throw new WriterException("No extras");
    }
    Uri uri = bundle.getParcelable(Intent.EXTRA_STREAM);
    if (uri == null) {
      throw new WriterException("No EXTRA_STREAM");
    }
    byte[] vcard;
    String vcardString;
    try (InputStream stream = activity.getContentResolver().openInputStream(uri)) {
      if (stream == null) {
        throw new WriterException("Can't open stream for " + uri);
      }
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      byte[] buffer = new byte[2048];
      int bytesRead;
      while ((bytesRead = stream.read(buffer)) > 0) {
        baos.write(buffer, 0, bytesRead);
      }
      vcard = baos.toByteArray();
      vcardString = new String(vcard, 0, vcard.length, StandardCharsets.UTF_8);
    } catch (IOException ioe) {
      throw new WriterException(ioe);
    }
    Log.d(TAG, "Encoding share intent content:");
    Log.d(TAG, vcardString);
    Result result = new Result(vcardString, vcard, null, BarcodeFormat.QR_CODE);
    ParsedResult parsedResult = ResultParser.parseResult(result);
    if (!(parsedResult instanceof AddressBookParsedResult)) {
      throw new WriterException("Result was not an address");
    }
    encodeQRCodeContents((AddressBookParsedResult) parsedResult);
    if (contents == null || contents.isEmpty()) {
      throw new WriterException("No content to encode");
    }
  }
223730
public void handleEOLMessage()
    {
        Iv2EndOfLogMessage msg = new Iv2EndOfLogMessage(m_partitionId);
        MPIEndOfLogTransactionState txnState = new MPIEndOfLogTransactionState(msg);
        MPIEndOfLogTask task = new MPIEndOfLogTask(m_mailbox, m_pendingTasks,
                                                   txnState, m_iv2Masters);
        m_pendingTasks.offer(task);
    }
799923
def handle_call(self, body, message):
        """"""
        try:
            r = self._DISPATCH(body, ticket=message.properties['reply_to'])
        except self.Next:
            # don't reply, delegate to other agents.
            pass
        else:
            self.reply(message, r)
415223
def get_my_contacts(self):
        
        my_contacts = self.wapi_functions.getMyContacts()
        return [Contact(contact, self) for contact in my_contacts]
564005
public final void startIntentSenderForResult(@NonNull final IntentSender intent, final int requestCode, @Nullable final Intent fillInIntent, final int flagsMask,
                                                 final int flagsValues, final int extraFlags, @Nullable final Bundle options) throws IntentSender.SendIntentException {
        router.startIntentSenderForResult(instanceId, intent, requestCode, fillInIntent, flagsMask, flagsValues, extraFlags, options);
    }
410467
public static Intent pickContactWithPhone() {
        Intent intent;
        if (isSupportsContactsV2()) {
            intent = pickContact(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
        } else { // pre Eclair, use old contacts API
            intent = pickContact(Contacts.Phones.CONTENT_TYPE);
        }
        return intent;
    }
1237227
function save_vcard()
    {
        $this->add_texts('localization', true);

        $uid     = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST);
        $mbox    = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST);
        $mime_id = rcube_utils::get_input_value('_part', rcube_utils::INPUT_POST);

        $rcmail  = rcmail::get_instance();
        $message = new rcube_message($uid, $mbox);

        if ($uid && $mime_id) {
            list($mime_id, $index) = explode(':', $mime_id);
            $part = $message->get_part_content($mime_id, null, true);
        }

        $error_msg = $this->gettext('vcardsavefailed');

        if ($part && ($vcards = rcube_vcard::import($part))
            && ($vcard = $vcards[$index]) && $vcard->displayname && $vcard->email
        ) {
            $CONTACTS = $this->get_address_book();
            $email    = $vcard->email[0];
            $contact  = $vcard->get_assoc();
            $valid    = true;

            // skip entries without an e-mail address or invalid
            if (empty($email) || !$CONTACTS->validate($contact, true)) {
                $valid = false;
            }
            else {
                // We're using UTF8 internally
                $email = rcube_utils::idn_to_utf8($email);

                // compare e-mail address
                $existing = $CONTACTS->search('email', $email, 1, false);
                // compare display name
                if (!$existing->count && $vcard->displayname) {
                    $existing = $CONTACTS->search('name', $vcard->displayname, 1, false);
                }

                if ($existing->count) {
                    $rcmail->output->command('display_message', $this->gettext('contactexists'), 'warning');
                    $valid = false;
                }
            }

            if ($valid) {
                $plugin = $rcmail->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => null));
                $contact = $plugin['record'];

                if (!$plugin['abort'] && $CONTACTS->insert($contact))
                    $rcmail->output->command('display_message', $this->gettext('addedsuccessfully'), 'confirmation');
                else
                    $rcmail->output->command('display_message', $error_msg, 'error');
            }
        }
        else {
            $rcmail->output->command('display_message', $error_msg, 'error');
        }

        $rcmail->output->send();
    }
774787
def get_contact_from_id(self, contact_id):
        
        contact = self.wapi_functions.getContact(contact_id)

        if contact is None:
            raise ContactNotFoundError("Contact {0} not found".format(contact_id))

        return Contact(contact, self)
299551
@Nullable
    public static Data onResult(@NonNull Context context, int resultCode, @Nullable Intent data) {
        if (resultCode != Activity.RESULT_OK || data == null || data.getData() == null) {
            return null;
        }

        Cursor cursor = null;
        try {
            cursor = context.getContentResolver().query(data.getData(),
                    new String[] {
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
                            ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                            ContactsContract.CommonDataKinds.Phone.NUMBER
                    },
                    null, null, null);

            if (cursor != null && cursor.moveToFirst()) {
                return new Data(cursor.getInt(0), cursor.getString(1), cursor.getString(2));
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }

        return null;
    }
18153
protected void handleParsedMessage() {

        InterChannelCallback cb = null;
        // use the read callback for early reads or temp messages requested
        // LI4335 - handle early reads too
        if (this.bEarlyReads || this.bTempResponsesUsed) {
            cb = getAppReadCallback();
        } else {
            cb = getAppWriteCallback();
        }
        VirtualConnection vc = null;
        do {
            this.numResponsesReceived++;
            if (!getResponseImpl().isTemporaryStatusCode()) {
                // a final response message was received
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Notifying app channel of final response.");
                }
                cb.complete(getVC());
                return;
            }

            // received a temporary response
            int code = getResponseImpl().getStatusCodeAsInt();
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Received response (#" + numberResponsesReceived() + "): " + code);
            }
            if (numberResponsesReceived() > getHttpConfig().getLimitOnNumberOfResponses()) {
                // too many temp responses
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Too many async temp responses received.");
                }
                cb.error(getVC(), new IOException("Max temp responses received: " + numberResponsesReceived()));
                return;
            }
            if (this.bTempResponsesUsed) {
                // call the app channel with this new response
                cb.complete(getVC());
                return;
            }
            if (getRequestImpl().isExpect100Continue()) {
                if (100 != code) {
                    // if the Expectation failed, then this connection is finished, so
                    // no need to reset any values.
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "Expect 100-continue failed with " + code);
                    }
                    setPersistent(false);
                    cb.error(getVC(), new ExpectationFailedException(code + " " + getResponseImpl().getReasonPhrase()));
                    return;
                } else if (1 == numberResponsesReceived() && isHeadersSentState()) {
                    // first 100-continue only, return to app channel immed but
                    // only if sendHeaders was used (meaning they want 100-continue)
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "Notifying channel of first 100-continue");
                    }
                    cb.complete(getVC());
                    return;
                }
            }
            // otherwise, this was a valid temporary response but the app channel
            // doesn't want to see it
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Ignoring temporary response...");
            }
            resetRead();
            if (setupReadBuffers(getHttpConfig().getIncomingHdrBufferSize(), false)) {
                // data is already available
                vc = getVC();
            } else {
                // read for the next bit of data
                vc = getTSC().getReadInterface().read(1, HttpOSCReadCallback.getRef(), false, getReadTimeout());
            }
            if (null != vc) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Attempting a parse of response data.");
                }
                vc = parseResponseMessageAsync();
            }
        } while (null != vc);
    }
986226
public Optional<ContactTokenDetails> getContact(String e164number) throws IOException {
    String              contactToken        = createDirectoryServerToken(e164number, true);
    ContactTokenDetails contactTokenDetails = this.pushServiceSocket.getContactTokenDetails(contactToken);

    if (contactTokenDetails != null) {
      contactTokenDetails.setNumber(e164number);
    }

    return Optional.fromNullable(contactTokenDetails);
  }
1107998
def dispatch(intent_request):
    

    logger.debug('dispatch userId={}, intentName={}'.format(intent_request['userId'], intent_request['currentIntent']['name']))

    intent_name = intent_request['currentIntent']['name']

    # Dispatch to your bot's intent handlers
    if intent_name == 'BookHotel':
        return book_hotel(intent_request)
    elif intent_name == 'BookCar':
        return book_car(intent_request)

    raise Exception('Intent with name ' + intent_name + ' not supported')
123686
def get_contacts(self, limit=100, offset=0, params={}):
        
        url = self.CONTACTS_URL + "?limit=%s&offset=%s" % (limit, offset)

        for key, value in params.items():
            if key is 'ids':
                value = ",".join(value)

            url += '&%s=%s' % (key, value)

        connection = Connection(self.token)
        connection.set_url(self.production, url)

        return connection.get_request()
483721
private void encodeContentsFromShareIntent(Intent intent) throws WriterException {
    // Check if this is a plain text encoding, or contact
    if (intent.hasExtra(Intent.EXTRA_STREAM)) {
      encodeFromStreamExtra(intent);
    } else {
      encodeFromTextExtras(intent);
    }
  }
197284
def get_contacts(self):
        
        all_contacts = self.wapi_functions.getAllContacts()
        return [Contact(contact, self) for contact in all_contacts]
621803
@SuppressWarnings("deprecation")
    public static Intent newPickContactWithPhoneIntent() {
        Intent intent;
        if (isContacts2ApiSupported()) {
            intent = newPickContactIntent(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
        } else {
            // pre Eclair, use old contacts API
            intent = newPickContactIntent(Contacts.Phones.CONTENT_TYPE);
        }
        return intent;
    }
330942
def intent(method):
    

    def wrapper(self, *args, **kwargs):
        try:
            return method(self, *args, **kwargs)
        except exceptions.MatrixError as e:
            if isinstance(e.original_exception,
                          matrix_client.errors.MatrixRequestError):
                self._handle_request_exception(e)
                # May still throw exception for other reasons; not handled
                return method(self, *args, **kwargs)
            else:
                raise e

    return wrapper