Code Monkey home page Code Monkey logo

jmap-dart-client's Introduction

JMAP Dart client

A JMAP client library to make JMAP method calls and process the responses.

We most notably use it to write the TMail Flutter application but you might reuse this library to write your own JMAP application.

We do welcome all contributions, given decent test coverage and acceptable code quality.

Please report any problem, any feature request, or discuss how you plan to use this lib in the repository issues.

Code samples

GetSession:

// create instance of httpClient with Dio
// using BasicAuth to config Dio
final httpClient = HttpClient(Dio());

final getSessionBuilder = GetSessionBuilder(httpClient);
final session = await getSessionBuilder.build().execute();

Fetching mailboxes

final processingInvocation = ProcessingInvocation();
final jmapRequestBuilder = JmapRequestBuilder(httpClient, processingInvocation);

final getMailboxMethod = GetMailboxMethod(accountId)
  ..addProperties(Properties({'role', 'name'}));

final queryInvocation = jmapRequestBuilder.invocation(getMailboxMethod);

final responseObject = await (jmapRequestBuilder
    ..usings(getMailboxCreated.requiredCapabilities))
  .build()
  .execute();

final getMailboxResponse = responseObject.parse<GetMailboxResponse>(
  queryInvocation.methodCallId,
  GetMailboxResponse.deserialize);

Get emails in Mailbox

final processingInvocation = ProcessingInvocation();

final jmapRequestBuilder = JmapRequestBuilder(httpClient, processingInvocation);

final queryEmailMethod = QueryEmailMethod(accountId)
  ..addPosition(0)
  ..addLimit(UnsignedInt(20))
  ..addSorts({EmailComparator(EmailComparatorProperty.sentAt)..setIsAscending(false)})
  ..addFilters(EmailFilterCondition(inMailbox: inBoxId));

final queryEmailInvocation = jmapRequestBuilder.invocation(queryEmailMethod);

final getEmailMethod = GetEmailMethod(accountId)
  ..addProperties(Properties({'id', 'subject','from', 'keywords', 'sentAt', 'preview', 'hasAttachment'}))
  ..addReferenceIds(processingInvocation.createResultReference(
    queryEmailInvocation.methodCallId,
    ReferencePath.idsPath));

final getEmailInvocation = jmapRequestBuilder.invocation(getEmailMethod);

final responseObject = await (jmapRequestBuilder
    ..usings(getEmailMethod.requiredCapabilities))
  .build()
  .execute();

final getEmailResponse = responseObject.parse<GetEmailResponse>(
    getEmailInvocation.methodCallId, 
    GetEmailResponse.deserialize);

jmap-dart-client's People

Contributors

chibenwa avatar dab246 avatar hoangdat avatar manhntx avatar nqhhdev avatar sherlockvn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.