clickLinkInLatestEmail method

Future<String> clickLinkInLatestEmail(
  1. String emailAddr, {
  2. bool replaceWithHomeserver = true,
  3. bool asPost = false,
  4. String? contains,
})

Implementation

Future<String> clickLinkInLatestEmail(
  String emailAddr, {
  bool replaceWithHomeserver = true,
  bool asPost = false,
  String? contains,
}) async {
  var link = await getLinkInLatestEmail(emailAddr, contains: contains);
  if (replaceWithHomeserver) {
    final homeserver = Uri.parse(Env.defaultHomeserverUrl);
    print('updating with $homeserver');
    link = link.replace(
      scheme: homeserver.scheme,
      host: homeserver.host,
      port: homeserver.port,
    );
  }
  print('Fetching $link');
  late http.Response resp;
  if (asPost) {
    resp = await http.post(link);
  } else {
    resp = await http.get(link);
  }

  assert(
    resp.statusCode == 200,
    'Error fetching $link [${resp.statusCode}]: ${resp.body}',
  );
  return resp.body;
}