Fetch email data

The app fetches the structured data that contains your email data.

Contents

Check if a config file is present

To check if there's a config file in its root directory, the app attempts to retrieve a file called "config".

Get file

GET /nfs/file/:rootPath/:filePath
nfs_actions.js
export const getConfigFile = token => {
  return {
    type: ACTION_TYPES.GET_CONFIG_FILE,
    payload: {
      request: {
        url: `/nfs/file/${CONSTANTS.ROOT_PATH}/config`,
        headers: {
          'Authorization': token,
          Range: 'bytes=0-'
        },
        responseType: 'arraybuffer'
      }
    }
  };
};

If a config file is not found

The app will create a root structured data with a random ID. All structured data items need to have an ID that is 32 bytes long. Therefore, the app generates a 32 bytes long random ID using this function:

app_utils.js
export const generateStructredDataId = () => {
  return base64.encode(crypto.randomBytes(32).toString('base64'));
};

The root structured data will be used to store your email data (your email ID and your saved emails). This data can be represented using a simple JSON format:

{
  "id": "",
  "saved": []
}

Get a cipher options handle

First, the app fetches a cipher options handle for symmetric encryption.

Get cipher options handle

/cipher-opts/:encType/:keyHandle?
cipher-opts_actions.js
export const getCipherOptsHandle = (token, encType, keyHandle='') => ({
  type: ACTION_TYPES.GET_CIPHER_OPTS_HANDLE,
  payload: {
    request: {
      url: `/cipher-opts/${encType}/${keyHandle}`,
      headers: {
        'Authorization': token,
      }
    }
  }
});

Create a root structured data

Your root structured data is encrypted using symmetric encryption. This means that no one else can read its content. Only you can decrypt it. Also, since we don't need versioning (we only want to show the latest data), we create an unversioned structured data (type tag 500).

Create structured data

POST /structured-data
structured_data_actions.js
export const createStructuredData = (token, name, data, cipherHandle) => ({
  type: ACTION_TYPES.CREATE_STRUCTURED_DATA,
  payload: {
    request: {
      method: 'post',
      url: '/structured-data',
      headers: {
        'Authorization': token
      },
      data: {
        name,
        typeTag: CONSTANTS.TAG_TYPE.DEFAULT,
        cipherOpts: cipherHandle,
        data: new Buffer(JSON.stringify(data)).toString('base64')
      }
    }
  }
});

Drop the cipher handle

The app drops the "cipher options" handle for symmetric encryption.

Drop cipher options handle

DELETE /cipher-opts/:handleId
cipher-opts_actions.js
export const deleteCipherOptsHandle = (token, handleId) => ({
  type: ACTION_TYPES.DELETE_CIPHER_OPTS_HANDLE,
  payload: {
    request: {
      method: 'delete',
      url: `/cipher-opts/${handleId}`,
      headers: {
        'Authorization': token,
      }
    }
  }
});

Save the root structured data

The app saves your root structured data to the SAFE Network.

Save structured data

PUT /structured-data/:handleId
structured_data_actions.js
export const putStructuredData = (token, handleId) => ({
  type: ACTION_TYPES.PUT_STRUCTURED_DATA,
  payload: {
    request: {
      method: 'put',
      url: `/structured-data/${handleId}`,
      headers: {
        'Authorization': token
      }
    }
  }
});

Create a config file

After your root structured data is successfully created, the app stores its ID in a config file. That way, the app will be able to retrieve your email data in the future.

This config file is stored in the app's root directory, which is private. Therefore, it will automatically be encrypted and no one else will be able to read it.

Create file

POST /nfs/file/:rootPath/:filePath
nfs_actions.js
export const writeConfigFile = (token, coreId) => {
  return {
    type: ACTION_TYPES.WRITE_CONFIG_FILE,
    payload: {
      request: {
        method: 'post',
        url: `/nfs/file/${CONSTANTS.ROOT_PATH}/config`,
        headers: {
          'Authorization': token,
          'Content-Type': 'plain/text'
        },
        data: new Uint8Array(Buffer(coreId))
      }
    }
  }
};

After the config file is successfully created, the app transitions to the Create Account page.

Create Account page

If a config file is found

The app will fetch your email data (email ID and saved emails) using the ID stored in the config file.

Get a data identifier handle

First, the app fetches a data identifier handle using the ID of your root structured data.

Get data ID handle

POST /data-id/structured-data
data_id_handle_actions.js
export const getStructuredDataIdHandle = (token, name, typeTag) => ({
  type: ACTION_TYPES.GET_STRUCTURED_DATA_ID_HANDLE,
  payload: {
    request: {
      method: 'post',
      url: '/data-id/structured-data',
      headers: {
        'Authorization': token
      },
      data: {
        typeTag,
        name
      }
    }
  }
});

Get a structured data handle

The app fetches a structured data handle using the data identifier handle of your root structured data.

Get structured data handle

GET /structured-data/handle/:dataIdHandle
structured_data_actions.js
export const fetchStructuredDataHandle = (token, dataIdHandle) => ({
  type: ACTION_TYPES.FETCH_STRUCTURE_DATA_HANDLE,
  payload: {
    request: {
      url: `/structured-data/handle/${dataIdHandle}`,
      headers: {
        'Authorization': token
      }
    }
  }
});

Fetch the root structured data

After the structured data handle is successfully retrieved, the app fetches the structured data that contains your email data.

Read structured data

GET /structured-data/:handleId/:version?
structured_data_actions.js
export const fetchStructuredData = (token, handleId) => ({
  type: ACTION_TYPES.FETCH_STRUCTURED_DATA,
  payload: {
    request: {
      url: `/structured-data/${handleId}`,
      headers: {
        'Authorization': token,
        'Content-Type': 'text/plain'
      }
    }
  }
});

If the structured data doesn't contain an email ID

If you hadn't created an email ID yet, the app transitions to the Create Account page.

Create Account page

If the structured data contains an email ID

If you had already created an email ID, the app transitions to the Inbox page.

Inbox page

results matching ""

    No results matching ""