up
This commit is contained in:
parent
867a2c8ebf
commit
e99de57edc
24 changed files with 11772 additions and 187 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1159,6 +1159,7 @@ dependencies = [
|
|||
"async-std",
|
||||
"mailparse",
|
||||
"notmuch",
|
||||
"percent-encoding",
|
||||
"serde",
|
||||
"toml",
|
||||
]
|
||||
|
|
|
@ -13,5 +13,6 @@ ammonia = "3"
|
|||
async-std = "1.5.0"
|
||||
mailparse = "0.12.0"
|
||||
notmuch = "0.6.0"
|
||||
percent-encoding = "2.1.0"
|
||||
serde = "1.0.106"
|
||||
toml = "0.5.0"
|
||||
|
|
23
frontend/.gitignore
vendored
Normal file
23
frontend/.gitignore
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
68
frontend/README.md
Normal file
68
frontend/README.md
Normal file
|
@ -0,0 +1,68 @@
|
|||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
### `yarn start`
|
||||
|
||||
Runs the app in the development mode.<br />
|
||||
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
|
||||
|
||||
The page will reload if you make edits.<br />
|
||||
You will also see any lint errors in the console.
|
||||
|
||||
### `yarn test`
|
||||
|
||||
Launches the test runner in the interactive watch mode.<br />
|
||||
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||
|
||||
### `yarn build`
|
||||
|
||||
Builds the app for production to the `build` folder.<br />
|
||||
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||
|
||||
The build is minified and the filenames include the hashes.<br />
|
||||
Your app is ready to be deployed!
|
||||
|
||||
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||
|
||||
### `yarn eject`
|
||||
|
||||
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
|
||||
|
||||
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||
|
||||
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
|
||||
|
||||
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
|
||||
|
||||
## Learn More
|
||||
|
||||
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||
|
||||
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||
|
||||
### Code Splitting
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
|
||||
|
||||
### Analyzing the Bundle Size
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
|
||||
|
||||
### Making a Progressive Web App
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
|
||||
|
||||
### Advanced Configuration
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
|
||||
|
||||
### Deployment
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
|
||||
|
||||
### `yarn build` fails to minify
|
||||
|
||||
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
|
15
frontend/layout.js
Normal file
15
frontend/layout.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import Container from "@material-ui/core/Container";
|
||||
import Grid from "@material-ui/core/Grid";
|
||||
|
||||
export default ({ left, right }) => (
|
||||
<Container maxWidth="">
|
||||
<Grid container spacing={1}>
|
||||
<Grid item xs={4}>
|
||||
{left}
|
||||
</Grid>
|
||||
<Grid item xs={8}>
|
||||
{right}
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Container>
|
||||
);
|
10
frontend/list.js
Normal file
10
frontend/list.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
import { List, ListItem, ListItemIcon, ListItemText } from '@material-ui/core'
|
||||
|
||||
export default (items = [{}]) => {
|
||||
items.map((i) => (
|
||||
<ListItem>
|
||||
<ListItemText primary={i.subject} />
|
||||
</ListItem>
|
||||
))
|
||||
return <List></List>
|
||||
}
|
38
frontend/package.json
Normal file
38
frontend/package.json
Normal file
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"name": "frontend",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@material-ui/core": "^4.9.12",
|
||||
"@material-ui/icons": "^4.9.1",
|
||||
"@material-ui/lab": "^4.0.0-alpha.51",
|
||||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.3.2",
|
||||
"@testing-library/user-event": "^7.1.2",
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-scripts": "3.4.1"
|
||||
},
|
||||
"proxy": "http://localhost:8088",
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"eject": "react-scripts eject"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "react-app"
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
">0.2%",
|
||||
"not dead",
|
||||
"not op_mini all"
|
||||
],
|
||||
"development": [
|
||||
"last 1 chrome version",
|
||||
"last 1 firefox version",
|
||||
"last 1 safari version"
|
||||
]
|
||||
}
|
||||
}
|
BIN
frontend/public/favicon.ico
Normal file
BIN
frontend/public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
43
frontend/public/index.html
Normal file
43
frontend/public/index.html
Normal file
|
@ -0,0 +1,43 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
</body>
|
||||
</html>
|
BIN
frontend/public/logo192.png
Normal file
BIN
frontend/public/logo192.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
BIN
frontend/public/logo512.png
Normal file
BIN
frontend/public/logo512.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
25
frontend/public/manifest.json
Normal file
25
frontend/public/manifest.json
Normal file
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
3
frontend/public/robots.txt
Normal file
3
frontend/public/robots.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
43
frontend/src/App.js
Normal file
43
frontend/src/App.js
Normal file
|
@ -0,0 +1,43 @@
|
|||
import React from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
import Layout from "./component/Layout";
|
||||
import List from "./component/List";
|
||||
import Thread from "./component/Thread";
|
||||
import Search from "./component/Search";
|
||||
|
||||
export default function Index() {
|
||||
const [query, setQuery] = useState("tag:inbox");
|
||||
const leftup = <Search setQuery={setQuery} />;
|
||||
|
||||
const [threads, setThreads] = useState({
|
||||
count: 0,
|
||||
threads: [{}],
|
||||
});
|
||||
useEffect(() => {
|
||||
fetch(`/search/${query}/0/30`)
|
||||
.then((response) => response.json())
|
||||
.then(
|
||||
(data) => setThreads(data),
|
||||
(error) => console.log(error)
|
||||
);
|
||||
}, [query]);
|
||||
|
||||
const [thread, setThread] = useState("");
|
||||
const [threadSpec, setThreadSpec] = useState({ message_ids: [] });
|
||||
useEffect(() => {
|
||||
if (thread == "") {
|
||||
return;
|
||||
}
|
||||
fetch(`/thread/${thread}`)
|
||||
.then((response) => response.json())
|
||||
.then(
|
||||
(data) => setThreadSpec(data),
|
||||
(error) => console.log(error)
|
||||
);
|
||||
}, [thread]);
|
||||
|
||||
const left = <List items={threads.threads} setThread={setThread} />;
|
||||
const right = <Thread spec={threadSpec} />;
|
||||
return <Layout leftup={leftup} left={left} right={right}></Layout>;
|
||||
}
|
18
frontend/src/component/Layout.js
Normal file
18
frontend/src/component/Layout.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import React from "react";
|
||||
|
||||
import Container from "@material-ui/core/Container";
|
||||
import Grid from "@material-ui/core/Grid";
|
||||
|
||||
export default ({ leftup, left, right }) => (
|
||||
<Container>
|
||||
<Grid container spacing={1}>
|
||||
<Grid item xs={4}>
|
||||
{leftup}
|
||||
{left}
|
||||
</Grid>
|
||||
<Grid item xs={8}>
|
||||
{right}
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Container>
|
||||
);
|
20
frontend/src/component/List.js
Normal file
20
frontend/src/component/List.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
import React from "react";
|
||||
|
||||
import { List, ListItem, ListItemText } from "@material-ui/core";
|
||||
|
||||
export default ({ items = [{}], setThread }) => {
|
||||
const handleThreadChange = (e, thread) => {
|
||||
e.preventDefault();
|
||||
setThread(thread.thread_id);
|
||||
};
|
||||
|
||||
const list = items.map((i) => (
|
||||
<ListItem button dense key={i.thread_id}>
|
||||
<ListItemText
|
||||
primary={i.subject}
|
||||
onClick={(e) => handleThreadChange(e, i)}
|
||||
/>
|
||||
</ListItem>
|
||||
));
|
||||
return <List>{list}</List>;
|
||||
};
|
58
frontend/src/component/Message.js
Normal file
58
frontend/src/component/Message.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
import React from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
CardActionArea,
|
||||
CardContent,
|
||||
Chip,
|
||||
Divider,
|
||||
Typography,
|
||||
} from "@material-ui/core";
|
||||
|
||||
export default ({ messageId }) => {
|
||||
const [message, setMessage] = useState({
|
||||
tags: [],
|
||||
from: "",
|
||||
to: "",
|
||||
cc: "",
|
||||
bcc: "",
|
||||
});
|
||||
useEffect(() => {
|
||||
fetch(`/message/${encodeURIComponent(messageId)}`)
|
||||
.then((response) => response.json())
|
||||
.then(
|
||||
(data) => setMessage(data),
|
||||
(error) => console.log(error)
|
||||
);
|
||||
}, []);
|
||||
|
||||
function body(message) {
|
||||
return { __html: message.body };
|
||||
}
|
||||
|
||||
const chips = message.tags.map((tag) => {
|
||||
return <Chip size="small" label={tag} />;
|
||||
});
|
||||
return (
|
||||
<Card key={messageId}>
|
||||
<CardContent>
|
||||
<Typography variant="h5" component="h2">
|
||||
{message.subject}
|
||||
</Typography>
|
||||
<div>
|
||||
From: {message.from}
|
||||
<br />
|
||||
To: {message.to}
|
||||
<br />
|
||||
</div>
|
||||
<div>{chips}</div>
|
||||
<Divider />
|
||||
<div dangerouslySetInnerHTML={body(message)}></div>
|
||||
</CardContent>
|
||||
<CardActionArea>
|
||||
<Button color="primary">Reply</Button>
|
||||
</CardActionArea>
|
||||
</Card>
|
||||
);
|
||||
};
|
52
frontend/src/component/Search.js
Normal file
52
frontend/src/component/Search.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
import React from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
import { Container, TextField } from "@material-ui/core";
|
||||
import { Autocomplete } from "@material-ui/lab";
|
||||
|
||||
export default ({ setQuery }) => {
|
||||
const [search, setSearch] = useState(["tag:inbox"]);
|
||||
|
||||
function handleSearchChange(event, value) {
|
||||
console.log(event);
|
||||
console.log(value);
|
||||
setSearch(value);
|
||||
setQuery(value.join(" "));
|
||||
}
|
||||
|
||||
const [options, setOptions] = useState([]);
|
||||
const handleSubSearchChange = (event, value, reason) => {
|
||||
const [kind, ...q] = value.split(":");
|
||||
const qq = q.join(":");
|
||||
fetch(`/autocomplete/${kind}/${qq}`)
|
||||
.then((response) => response.json())
|
||||
.then(
|
||||
(data) => {
|
||||
if (data) {
|
||||
setOptions(data.results || []);
|
||||
}
|
||||
},
|
||||
(error) => console.log(error)
|
||||
);
|
||||
};
|
||||
|
||||
const [autocomplete, setAutocomplete] = useState("");
|
||||
useEffect(() => {
|
||||
setAutocomplete(
|
||||
<Autocomplete
|
||||
multiple
|
||||
id="search"
|
||||
value={search}
|
||||
onChange={handleSearchChange}
|
||||
onInputChange={handleSubSearchChange}
|
||||
options={options}
|
||||
renderInput={(params) => (
|
||||
<TextField {...params} label="query" variant="outlined" />
|
||||
)}
|
||||
size="small"
|
||||
/>
|
||||
);
|
||||
}, [options]);
|
||||
|
||||
return autocomplete;
|
||||
};
|
11
frontend/src/component/Thread.js
Normal file
11
frontend/src/component/Thread.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
import React from "react";
|
||||
import { Card, CardContent } from "@material-ui/core";
|
||||
|
||||
import Message from "./Message";
|
||||
|
||||
export default ({ spec }) => {
|
||||
const messages = spec.message_ids.map((message_id) => {
|
||||
return <Message key={message_id} messageId={message_id}></Message>;
|
||||
});
|
||||
return <div>{messages}</div>;
|
||||
};
|
16
frontend/src/index.js
Normal file
16
frontend/src/index.js
Normal file
|
@ -0,0 +1,16 @@
|
|||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import App from './App';
|
||||
import * as serviceWorker from './serviceWorker';
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>,
|
||||
document.getElementById('root')
|
||||
);
|
||||
|
||||
// If you want your app to work offline and load faster, you can change
|
||||
// unregister() to register() below. Note this comes with some pitfalls.
|
||||
// Learn more about service workers: https://bit.ly/CRA-PWA
|
||||
serviceWorker.unregister();
|
141
frontend/src/serviceWorker.js
Normal file
141
frontend/src/serviceWorker.js
Normal file
|
@ -0,0 +1,141 @@
|
|||
// This optional code is used to register a service worker.
|
||||
// register() is not called by default.
|
||||
|
||||
// This lets the app load faster on subsequent visits in production, and gives
|
||||
// it offline capabilities. However, it also means that developers (and users)
|
||||
// will only see deployed updates on subsequent visits to a page, after all the
|
||||
// existing tabs open on the page have been closed, since previously cached
|
||||
// resources are updated in the background.
|
||||
|
||||
// To learn more about the benefits of this model and instructions on how to
|
||||
// opt-in, read https://bit.ly/CRA-PWA
|
||||
|
||||
const isLocalhost = Boolean(
|
||||
window.location.hostname === 'localhost' ||
|
||||
// [::1] is the IPv6 localhost address.
|
||||
window.location.hostname === '[::1]' ||
|
||||
// 127.0.0.0/8 are considered localhost for IPv4.
|
||||
window.location.hostname.match(
|
||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||
)
|
||||
);
|
||||
|
||||
export function register(config) {
|
||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
// from what our page is served on. This might happen if a CDN is used to
|
||||
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
if (isLocalhost) {
|
||||
// This is running on localhost. Let's check if a service worker still exists or not.
|
||||
checkValidServiceWorker(swUrl, config);
|
||||
|
||||
// Add some additional logging to localhost, pointing developers to the
|
||||
// service worker/PWA documentation.
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log(
|
||||
'This web app is being served cache-first by a service ' +
|
||||
'worker. To learn more, visit https://bit.ly/CRA-PWA'
|
||||
);
|
||||
});
|
||||
} else {
|
||||
// Is not localhost. Just register service worker
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function registerValidSW(swUrl, config) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
.then(registration => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
if (installingWorker == null) {
|
||||
return;
|
||||
}
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// At this point, the updated precached content has been fetched,
|
||||
// but the previous service worker will still serve the older
|
||||
// content until all client tabs are closed.
|
||||
console.log(
|
||||
'New content is available and will be used when all ' +
|
||||
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
|
||||
);
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onUpdate) {
|
||||
config.onUpdate(registration);
|
||||
}
|
||||
} else {
|
||||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// "Content is cached for offline use." message.
|
||||
console.log('Content is cached for offline use.');
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onSuccess) {
|
||||
config.onSuccess(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl, config) {
|
||||
// Check if the service worker can be found. If it can't reload the page.
|
||||
fetch(swUrl, {
|
||||
headers: { 'Service-Worker': 'script' },
|
||||
})
|
||||
.then(response => {
|
||||
// Ensure service worker exists, and that we really are getting a JS file.
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (
|
||||
response.status === 404 ||
|
||||
(contentType != null && contentType.indexOf('javascript') === -1)
|
||||
) {
|
||||
// No service worker found. Probably a different app. Reload the page.
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Service worker found. Proceed as normal.
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.log(
|
||||
'No internet connection found. App is running in offline mode.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready
|
||||
.then(registration => {
|
||||
registration.unregister();
|
||||
})
|
||||
.catch(error => {
|
||||
console.error(error.message);
|
||||
});
|
||||
}
|
||||
}
|
11026
frontend/yarn.lock
Normal file
11026
frontend/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
26
src/main.rs
26
src/main.rs
|
@ -9,6 +9,7 @@ use ammonia;
|
|||
use async_std::sync::{Arc, Mutex};
|
||||
use mailparse::body::Body;
|
||||
use notmuch;
|
||||
use percent_encoding;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
@ -33,9 +34,13 @@ async fn main() -> std::io::Result<()> {
|
|||
App::new()
|
||||
.data(data.clone())
|
||||
.route("/", web::get().to(index))
|
||||
.route("/autocomplete/{kind}", web::get().to(autocomplete))
|
||||
.route("/autocomplete/{kind}/", web::get().to(autocomplete))
|
||||
.route("/autocomplete/{kind}/{query}", web::get().to(autocomplete))
|
||||
.route("/search/{query}", web::get().to(search))
|
||||
.route("/search/{query}/", web::get().to(search))
|
||||
.route("/search/{query}/{start}", web::get().to(search))
|
||||
.route("/search/{query}/{start}/", web::get().to(search))
|
||||
.route("/search/{query}/{start}/{count}", web::get().to(search))
|
||||
.route("/thread/{thread_id}", web::get().to(thread))
|
||||
.route("/message/{message_id}", web::get().to(message))
|
||||
|
@ -76,7 +81,7 @@ impl From<Vec<String>> for AutocompleteResults {
|
|||
|
||||
async fn autocomplete(data: web::Data<Data>, req: HttpRequest) -> impl Responder {
|
||||
let kind = Autocomplete::from(req.match_info().get("kind").unwrap());
|
||||
let query = req.match_info().get("query").unwrap(); // TODO: use
|
||||
let query = req.match_info().get("query").unwrap_or(""); // TODO: use
|
||||
let mut results = HashSet::new();
|
||||
let db = data.db.lock().await;
|
||||
match kind {
|
||||
|
@ -89,7 +94,7 @@ async fn autocomplete(data: web::Data<Data>, req: HttpRequest) -> impl Responder
|
|||
.take(1000)
|
||||
.for_each(|msg| {
|
||||
msg.tags().for_each(|tag| {
|
||||
results.insert(tag);
|
||||
results.insert(format!("tag:{}", tag));
|
||||
})
|
||||
}),
|
||||
Autocomplete::From => db
|
||||
|
@ -209,7 +214,9 @@ struct ThreadSpec {
|
|||
impl From<¬much::Thread<'_, '_>> for ThreadSpec {
|
||||
fn from(thread: ¬much::Thread) -> Self {
|
||||
let t = Thread::from(thread);
|
||||
let message_ids = thread.messages().map(|msg| msg.id().to_string()).collect();
|
||||
let mut message_ids: Vec<String> =
|
||||
thread.messages().map(|msg| msg.id().to_string()).collect();
|
||||
message_ids.reverse();
|
||||
ThreadSpec {
|
||||
thread_id: t.thread_id,
|
||||
count: t.count,
|
||||
|
@ -237,6 +244,7 @@ struct Message {
|
|||
bcc: String,
|
||||
date: i64,
|
||||
subject: String,
|
||||
tags: Vec<String>,
|
||||
body: String,
|
||||
attachments: Vec<String>,
|
||||
}
|
||||
|
@ -274,14 +282,16 @@ where
|
|||
_ => panic!("unsupported body"),
|
||||
};
|
||||
//let body = ammonia::clean(&body);
|
||||
let body = ammonia::Builder::new()
|
||||
let mut body = ammonia::Builder::new()
|
||||
.attribute_filter(|tag, attr, val| match (tag, attr) {
|
||||
("img", "src") => None,
|
||||
_ => Some(val.into()),
|
||||
})
|
||||
.clean(&body)
|
||||
.to_string();
|
||||
let body = format!("<div style=\"white-space: pre-wrap\">{}</div>", body);
|
||||
if mail.ctype.mimetype != "text/html" {
|
||||
body = format!("<div style=\"white-space: pre-wrap\">{}</div>", body);
|
||||
}
|
||||
Message {
|
||||
from: message.header("from").unwrap().unwrap().to_string(),
|
||||
to: message.header("to").unwrap().unwrap().to_string(),
|
||||
|
@ -297,6 +307,7 @@ where
|
|||
.to_string(),
|
||||
date: message.date(),
|
||||
subject: message.header("subject").unwrap().unwrap().to_string(),
|
||||
tags: message.tags().collect(),
|
||||
body: body,
|
||||
attachments: Vec::new(),
|
||||
}
|
||||
|
@ -305,14 +316,13 @@ where
|
|||
|
||||
async fn message(data: web::Data<Data>, req: HttpRequest) -> impl Responder {
|
||||
let message_id = req.match_info().get("message_id").unwrap();
|
||||
println!("mid:{}", message_id);
|
||||
let message_id = percent_encoding::percent_decode_str(&message_id).decode_utf8_lossy();
|
||||
let db = data.db.lock().await;
|
||||
let query = db.create_query(&format!("mid:{}", message_id)).unwrap();
|
||||
let message = query.search_messages().unwrap().next().unwrap();
|
||||
//HttpResponse::Ok().json(Message::from(&message))
|
||||
HttpResponse::Ok()
|
||||
.content_type("text/html;charset=utf-8")
|
||||
.body(Message::from(&message).body)
|
||||
.json(Message::from(&message))
|
||||
}
|
||||
|
||||
async fn index() -> impl Responder {
|
||||
|
|
317
web/index.html
317
web/index.html
|
@ -1,199 +1,162 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="https://unpkg.com/buefy/dist/buefy.min.css">
|
||||
<style>
|
||||
.maillist .tags {
|
||||
display: inline;
|
||||
}
|
||||
.maillist .tags {
|
||||
display: inline;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<section>
|
||||
<div id="app" class="container">
|
||||
<div class="row">
|
||||
<b-tabs v-model="activeTab">
|
||||
<b-tab-item label="List">
|
||||
<section class="section">
|
||||
<div class="">
|
||||
<div id="app" class="columns">
|
||||
<div class="column is-two-fifths">
|
||||
<div class="box">
|
||||
<b-taginput icon="magnify" placeholder="Search..." expanded v-model="mailSearch" autocomplete
|
||||
allow-new :data="mailSearchAutocomplete" @typing="getFilteredMailAddrs" @input="loadMails">
|
||||
</b-taginput>
|
||||
<b-table :data="mailTable" :loading="mailLoading" narrowed :row-class="() => 'maillist'"
|
||||
paginated backend-pagination :total="mailTotal" :per-page="mailLimit"
|
||||
@page-change="mailPageChange" @select="mailSelect">
|
||||
|
||||
<b-taginput
|
||||
icon="magnify"
|
||||
placeholder="Search..."
|
||||
expanded
|
||||
|
||||
v-model="mailSearch"
|
||||
|
||||
autocomplete
|
||||
allow-new
|
||||
:data="mailSearchAutocomplete"
|
||||
@typing="getFilteredMailAddrs"
|
||||
|
||||
@input="loadMails"
|
||||
>
|
||||
</b-taginput>
|
||||
<b-table :data="mailTable"
|
||||
:loading="mailLoading"
|
||||
narrowed
|
||||
:row-class="() => 'maillist'"
|
||||
|
||||
paginated
|
||||
backend-pagination
|
||||
:total="mailTotal"
|
||||
:per-page="mailLimit"
|
||||
@page-change="mailPageChange"
|
||||
|
||||
@select="mailSelect"
|
||||
>
|
||||
|
||||
<template slot-scope="props">
|
||||
<b-table-column field="date" label="Datum">
|
||||
{{ props.row.date}}
|
||||
</b-table-column>
|
||||
<b-table-column field="subject" label="Subject">
|
||||
<template slot-scope="props">
|
||||
<b-table-column field="date" label="Datum">
|
||||
{{ props.row.date}}
|
||||
</b-table-column>
|
||||
<b-table-column field="subject" label="Subject">
|
||||
<b-taglist attached>
|
||||
<b-tag v-for="tag in props.row.tags" type="is-info">
|
||||
{{ tag }}
|
||||
</b-tag>
|
||||
<b-tag type="is-success">{{ props.row.count }}</b-tag>
|
||||
</b-taglist>
|
||||
{{ props.row.subject}}
|
||||
</b-table-column>
|
||||
</template>
|
||||
</b-table>
|
||||
</div>
|
||||
</div>
|
||||
<div class="column">
|
||||
<div class="box" v-for="message_id in openThread.message_ids" @key="message_id">
|
||||
<h2>{{openThread.subject}}</h2>
|
||||
<b-taglist attached>
|
||||
<b-tag v-for="tag in props.row.tags" type="is-info">
|
||||
<b-tag v-for="tag in openThreadMessages[message_id].tags" type="is-info">
|
||||
{{ tag }}
|
||||
</b-tag>
|
||||
<b-tag type="is-success">{{ props.row.count }}</b-tag>
|
||||
</b-taglist>
|
||||
{{ props.row.subject}}
|
||||
</b-table-column>
|
||||
</template>
|
||||
</b-table>
|
||||
|
||||
</b-tab-item>
|
||||
<b-tab-item v-for="(thread, thread_id) in mailsOpen"
|
||||
:key="thread_id"
|
||||
>
|
||||
<template slot="header">
|
||||
{{ thread.subject | truncate }}
|
||||
<b-tag rounded>{{ thread.count }}</b-tag>
|
||||
<button type="button"
|
||||
class="delete"
|
||||
@click="closeActiveTab(thread_id)"
|
||||
></button>
|
||||
</template>
|
||||
<div class="box" v-for="message_id in thread.message_ids"
|
||||
key="message_id">
|
||||
<iframe style="width: 100%"
|
||||
:src="`/message/${message_id}`"
|
||||
onload="javascript:(function(o){o.style.height=o.contentWindow.document.body.scrollHeight+'px';}(this));"
|
||||
></iframe>
|
||||
</b-taglist>
|
||||
<hr>
|
||||
<div v-html="openThreadMessages[message_id].body"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</b-tab-item>
|
||||
</b-tabs>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://unpkg.com/vue"></script>
|
||||
<script src="https://unpkg.com/buefy/dist/buefy.min.js"></script>
|
||||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
|
||||
<script src="https://unpkg.com/vue"></script>
|
||||
<script src="https://unpkg.com/buefy/dist/buefy.min.js"></script>
|
||||
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
|
||||
|
||||
<script>
|
||||
new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
mailTable: [],
|
||||
mailSearch: ['tag:inbox'],
|
||||
mailLoading: false,
|
||||
mailStart: 0,
|
||||
mailLimit: 30,
|
||||
mailTotal: 0,
|
||||
mailRowContent: {},
|
||||
mailAddrs: [],
|
||||
mailTags: [],
|
||||
mailBody: '',
|
||||
mailSearchAutocomplete: [],
|
||||
searchTimeout: null,
|
||||
<script>
|
||||
new Vue({
|
||||
el: '#app',
|
||||
data: {
|
||||
mailTable: [],
|
||||
mailSearch: ['tag:inbox'],
|
||||
mailLoading: false,
|
||||
mailStart: 0,
|
||||
mailLimit: 30,
|
||||
mailTotal: 0,
|
||||
mailRowContent: {},
|
||||
mailAddrs: [],
|
||||
mailTags: [],
|
||||
mailBody: '',
|
||||
mailSearchAutocomplete: [],
|
||||
searchTimeout: null,
|
||||
openThread: {},
|
||||
openThreadMessages: [],
|
||||
},
|
||||
filters: {
|
||||
truncate(value) {
|
||||
if (value.length > 11) {
|
||||
value = value.substring(0, 10) + '…';
|
||||
}
|
||||
return value;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
|
||||
activeTab: 0,
|
||||
mailsOpen: {},
|
||||
},
|
||||
filters: {
|
||||
truncate(value) {
|
||||
if (value.length > 11) {
|
||||
value = value.substring(0, 10) + '…';
|
||||
loadMails() {
|
||||
this.mailLoading = true;
|
||||
search = this.mailSearch.join(' ');
|
||||
axios.get(`/search/${search}/${this.mailStart}/${this.mailLimit}`)
|
||||
.then(({ data }) => {
|
||||
this.mailTable = data.threads;
|
||||
this.mailTotal = data.count;
|
||||
this.mailLoading = false;
|
||||
})
|
||||
.catch(({ request }) => {
|
||||
this.mailTable = [];
|
||||
this.mailTotal = 0;
|
||||
this.mailLoading = false;
|
||||
})
|
||||
},
|
||||
|
||||
getFilteredMailAddrs(text) {
|
||||
kind = text.split(':', 1);
|
||||
text = text.substr(text.indexOf(':') + 1);
|
||||
axios.get(`/autocomplete/${kind}/${text}`)
|
||||
.then(({ data }) => {
|
||||
this.mailSearchAutocomplete = data.results.filter((option) => {
|
||||
return option.indexOf(text) >= 0;
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
mailPageChange(page) {
|
||||
this.mailStart = (page - 1) * this.mailLimit;
|
||||
this.loadMails();
|
||||
},
|
||||
|
||||
doMailSearch(search) {
|
||||
this.mailSearch = search;
|
||||
this.loadMails();
|
||||
},
|
||||
|
||||
debounceSearch(search) {
|
||||
if (this.searchTimeout) {
|
||||
clearTimeout(this.searchTimeout);
|
||||
}
|
||||
this.searchTimeout = setTimeout(() => {
|
||||
this.doMailSearch(search);
|
||||
}, 100);
|
||||
},
|
||||
|
||||
mailSelect(row) {
|
||||
axios.get(`/thread/${row.thread_id}`)
|
||||
.then(({ data }) => {
|
||||
this.openThread = data;
|
||||
this.openThreadMessages = {};
|
||||
data.message_ids.forEach((messageId) => {
|
||||
axios.get(`/message/${encodeURIComponent(messageId)}`)
|
||||
.then((data) => { this.$set(this.openThreadMessages, messageId, data.data) })
|
||||
})
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
},
|
||||
mounted() {
|
||||
this.loadMails();
|
||||
}
|
||||
return value;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
|
||||
loadMails() {
|
||||
this.mailLoading = true;
|
||||
search = this.mailSearch.join(' ');
|
||||
axios.get(`/search/${search}/${this.mailStart}/${this.mailLimit}`)
|
||||
.then(({data}) => {
|
||||
this.mailTable = data.threads;
|
||||
this.mailTotal = data.count;
|
||||
this.mailLoading = false;
|
||||
})
|
||||
.catch(({request}) => {
|
||||
this.mailTable = [];
|
||||
this.mailTotal = 0;
|
||||
this.mailLoading = false;
|
||||
})
|
||||
},
|
||||
|
||||
getFilteredMailAddrs(text) {
|
||||
kind = text.split(':', 1);
|
||||
text = text.substr(text.indexOf(':') + 1);
|
||||
if (text.length == 0) { return; }
|
||||
axios.get(`/autocomplete/${kind}/${text}`)
|
||||
.then(({data}) => {
|
||||
this.mailSearchAutocomplete = data.results.filter((option) => {
|
||||
return option.indexOf(text) >= 0;
|
||||
});
|
||||
})
|
||||
},
|
||||
|
||||
mailPageChange(page) {
|
||||
this.mailStart = (page - 1) * this.mailLimit;
|
||||
this.loadMails();
|
||||
},
|
||||
|
||||
doMailSearch(search) {
|
||||
this.mailSearch = search;
|
||||
this.loadMails();
|
||||
},
|
||||
|
||||
debounceSearch(search) {
|
||||
if (this.searchTimeout) {
|
||||
clearTimeout(this.searchTimeout);
|
||||
}
|
||||
this.searchTimeout = setTimeout(() => {
|
||||
this.doMailSearch(search);
|
||||
}, 100);
|
||||
},
|
||||
|
||||
mailSelect(row) {
|
||||
axios.get(`/thread/${row.thread_id}`)
|
||||
.then(({data}) => {
|
||||
console.log('hello');
|
||||
console.log(data);
|
||||
this.$set(this.mailsOpen, data.thread_id, data);
|
||||
this.$nextTick(() => {
|
||||
pos = Object.keys(this.mailsOpen).indexOf(data.thread_id);
|
||||
this.activeTab = pos + 1;
|
||||
});
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
closeActiveTab(thread_id) {
|
||||
delete this.mailsOpen[thread_id];
|
||||
this.mailsOpen = Object.assign({}, this.mailsOpen);
|
||||
this.activeTab--;
|
||||
}
|
||||
|
||||
},
|
||||
mounted() {
|
||||
this.loadMails();
|
||||
}
|
||||
})
|
||||
</script>
|
||||
</section>
|
||||
})
|
||||
</script>
|
||||
</div>
|
||||
</section>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue